Added XML::NodeSet#==
This method can be used to compare two NodeSet instances. By using XML::NodeSet#equal_nodes?() the need for exposing the "nodes" instance variable is also removed.
This commit is contained in:
parent
7e38e20586
commit
857ac517d5
|
@ -197,6 +197,28 @@ module Oga
|
||||||
return self.class.new(to_a | other.to_a)
|
return self.class.new(to_a | other.to_a)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# Returns `true` if the current node set and the one given in `other` are
|
||||||
|
# equal to each other.
|
||||||
|
#
|
||||||
|
# @param [Oga::XML::NodeSet] other
|
||||||
|
#
|
||||||
|
def ==(other)
|
||||||
|
return other.is_a?(NodeSet) && other.equal_nodes?(@nodes)
|
||||||
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# Returns `true` if the nodes given in `nodes` are equal to those
|
||||||
|
# specified in the current `@nodes` variable. This method allows two
|
||||||
|
# NodeSet instances to compare each other without the need of exposing
|
||||||
|
# `@nodes` to the public.
|
||||||
|
#
|
||||||
|
# @param [Array<Oga::XML::Node>] nodes
|
||||||
|
#
|
||||||
|
def equal_nodes?(nodes)
|
||||||
|
return @nodes == nodes
|
||||||
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
# Adds the nodes of the given node set to the current node set.
|
# Adds the nodes of the given node set to the current node set.
|
||||||
#
|
#
|
||||||
|
|
|
@ -278,6 +278,23 @@ describe Oga::XML::NodeSet do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context '#==' do
|
||||||
|
before do
|
||||||
|
node = Oga::XML::Node.new
|
||||||
|
@set1 = described_class.new([node])
|
||||||
|
@set2 = described_class.new([node])
|
||||||
|
@set3 = described_class.new
|
||||||
|
end
|
||||||
|
|
||||||
|
example 'return true if two node sets are equal' do
|
||||||
|
@set1.should == @set2
|
||||||
|
end
|
||||||
|
|
||||||
|
example 'return false if two node sets are not equal' do
|
||||||
|
@set1.should_not == @set3
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context '#concat' do
|
context '#concat' do
|
||||||
before do
|
before do
|
||||||
n1 = Oga::XML::Element.new(:name => 'a')
|
n1 = Oga::XML::Element.new(:name => 'a')
|
||||||
|
|
Loading…
Reference in New Issue