Added XML::Attribute#text

This allows attributes to also be used for axes such as "=".
This commit is contained in:
Yorick Peterse 2014-09-03 23:38:00 +02:00
parent 9b8e9f49c6
commit 81a62a6f00
3 changed files with 13 additions and 5 deletions

View File

@ -67,12 +67,16 @@ module Oga
end end
## ##
# Returns the value of the attribute.
#
# @return [String] # @return [String]
# #
def to_s def text
return value.to_s return value.to_s
end end
alias_method :to_s, :text
## ##
# @return [String] # @return [String]
# #

View File

@ -37,13 +37,13 @@ describe Oga::XML::Attribute do
end end
end end
context '#to_s' do context '#text' do
example 'return an empty String when there is no value' do example 'return an empty String when there is no value' do
described_class.new.to_s.should == '' described_class.new.text.should == ''
end end
example 'return the value if it is present' do example 'return the value if it is present' do
described_class.new(:value => 'a').to_s.should == 'a' described_class.new(:value => 'a').text.should == 'a'
end end
end end

View File

@ -3,7 +3,7 @@ require 'spec_helper'
describe Oga::XPath::Evaluator do describe Oga::XPath::Evaluator do
context 'equal operator' do context 'equal operator' do
before do before do
@document = parse('<root><a>10</a><b>10</b></root>') @document = parse('<root><a>10</a><b class="foo">10</b></root>')
@evaluator = described_class.new(@document) @evaluator = described_class.new(@document)
end end
@ -54,5 +54,9 @@ describe Oga::XPath::Evaluator do
example 'return true if a number and a node set wildcard are equal' do example 'return true if a number and a node set wildcard are equal' do
@evaluator.evaluate('10 = root/*').should == true @evaluator.evaluate('10 = root/*').should == true
end end
example 'return true if an attribute and string are equal' do
@evaluator.evaluate('root/b/@class = "foo"').should == true
end
end end
end end