Added XML::Attribute#text
This allows attributes to also be used for axes such as "=".
This commit is contained in:
parent
9b8e9f49c6
commit
81a62a6f00
|
@ -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]
|
||||
#
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue