Added XML::NodeSet#+ and XML::NodeSet#to_a
This commit is contained in:
parent
266c66569e
commit
9c661e1e60
|
@ -159,6 +159,26 @@ module Oga
|
||||||
return @nodes[index]
|
return @nodes[index]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# Converts the current set to an Array.
|
||||||
|
#
|
||||||
|
# @return [Array]
|
||||||
|
#
|
||||||
|
def to_a
|
||||||
|
return @nodes
|
||||||
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# Creates a new set based on the current and the specified set. The newly
|
||||||
|
# created set does not inherit ownership rules of the current set.
|
||||||
|
#
|
||||||
|
# @param [Oga::XML::NodeSet] other
|
||||||
|
# @return [Oga::XML::NodeSet]
|
||||||
|
#
|
||||||
|
def +(other)
|
||||||
|
return self.class.new(to_a + other.to_a)
|
||||||
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
# Removes the current nodes from their owning set. The nodes are *not*
|
# Removes the current nodes from their owning set. The nodes are *not*
|
||||||
# removed from the current set.
|
# removed from the current set.
|
||||||
|
|
|
@ -185,6 +185,30 @@ describe Oga::XML::NodeSet do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context '#to_a' do
|
||||||
|
before do
|
||||||
|
@n1 = Oga::XML::Element.new(:name => 'a')
|
||||||
|
@set = described_class.new([@n1])
|
||||||
|
end
|
||||||
|
|
||||||
|
example 'convert a set to an Array' do
|
||||||
|
@set.to_a.should == [@n1]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context '#+' do
|
||||||
|
before do
|
||||||
|
@n1 = Oga::XML::Element.new(:name => 'a')
|
||||||
|
@n2 = Oga::XML::Element.new(:name => 'b')
|
||||||
|
@set1 = described_class.new([@n1])
|
||||||
|
@set2 = described_class.new([@n2])
|
||||||
|
end
|
||||||
|
|
||||||
|
example 'merge two sets together' do
|
||||||
|
(@set1 + @set2).to_a.should == [@n1, @n2]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context '#remove' do
|
context '#remove' do
|
||||||
before do
|
before do
|
||||||
owner = Oga::XML::Element.new
|
owner = Oga::XML::Element.new
|
||||||
|
|
Loading…
Reference in New Issue