diff --git a/lib/oga/xml/node_set.rb b/lib/oga/xml/node_set.rb index 866e87a..b2d7f46 100644 --- a/lib/oga/xml/node_set.rb +++ b/lib/oga/xml/node_set.rb @@ -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. diff --git a/spec/oga/xml/node_set_spec.rb b/spec/oga/xml/node_set_spec.rb index e0a15b6..3204c3d 100644 --- a/spec/oga/xml/node_set_spec.rb +++ b/spec/oga/xml/node_set_spec.rb @@ -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