nodes/attributes support in to_compatible_types
This extends XPath::Conversion.to_compatible_types so that it can also take XML::Node and XML::Attribute objects as input.
This commit is contained in:
parent
376d016acd
commit
06ae1503d4
|
@ -10,11 +10,11 @@ module Oga
|
|||
# @return [Array]
|
||||
#
|
||||
def self.to_compatible_types(left, right)
|
||||
if left.is_a?(XML::NodeSet)
|
||||
if left.is_a?(XML::NodeSet) or left.respond_to?(:text)
|
||||
left = to_string(left)
|
||||
end
|
||||
|
||||
if right.is_a?(XML::NodeSet)
|
||||
if right.is_a?(XML::NodeSet) or right.respond_to?(:text)
|
||||
right = to_string(right)
|
||||
end
|
||||
|
||||
|
|
|
@ -12,6 +12,26 @@ describe Oga::XPath::Conversion do
|
|||
right.should == 'bar'
|
||||
end
|
||||
|
||||
it 'returns two Strings when using two Nodes' do
|
||||
n1 = Oga::XML::Text.new(:text => 'foo')
|
||||
n2 = Oga::XML::Text.new(:text => 'bar')
|
||||
|
||||
left, right = described_class.to_compatible_types(n1, n2)
|
||||
|
||||
left.should == 'foo'
|
||||
right.should == 'bar'
|
||||
end
|
||||
|
||||
it 'returns two Strings when using two Attributes' do
|
||||
n1 = Oga::XML::Attribute.new(:value => 'foo')
|
||||
n2 = Oga::XML::Attribute.new(:value => 'bar')
|
||||
|
||||
left, right = described_class.to_compatible_types(n1, n2)
|
||||
|
||||
left.should == 'foo'
|
||||
right.should == 'bar'
|
||||
end
|
||||
|
||||
it 'returns two Strings when using a NodeSet and Float' do
|
||||
set = node_set(Oga::XML::Text.new(:text => 'foo'))
|
||||
|
||||
|
|
Loading…
Reference in New Issue