Added NodeSet#concat.

This method allows two sets to be concatenated together without the need of
creating a 3rd node set (as is the case with NodeSet#+).
This commit is contained in:
Yorick Peterse 2014-09-05 10:07:22 +02:00
parent 8601cf6e74
commit bcdce306e5
2 changed files with 25 additions and 0 deletions

View File

@ -183,6 +183,15 @@ module Oga
return self.class.new(to_a | other.to_a)
end
##
# Adds the nodes of the given node set to the current node set.
#
# @param [Oga::XML::NodeSet] other
#
def concat(other)
other.each { |node| push(node) }
end
##
# Removes the current nodes from their owning set. The nodes are *not*
# removed from the current set.

View File

@ -235,6 +235,22 @@ describe Oga::XML::NodeSet do
end
end
context '#concat' 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 'concatenate two node sets' do
@set1.concat(@set2)
@set1.length.should == 2
end
end
context '#remove' do
before do
owner = Oga::XML::Element.new