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
##
# Returns the value of the attribute.
#
# @return [String]
#
def to_s
def text
return value.to_s
end
alias_method :to_s, :text
##
# @return [String]
#

View File

@ -37,13 +37,13 @@ describe Oga::XML::Attribute do
end
end
context '#to_s' do
context '#text' do
example 'return an empty String when there is no value' do
described_class.new.to_s.should == ''
described_class.new.text.should == ''
end
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

View File

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