Added Node#remove.
This method can be used to remove individual nodes without first having to retrieve the NodeSet they are stored in.
This commit is contained in:
parent
e334e50ca6
commit
8b381ac970
|
@ -130,6 +130,15 @@ module Oga
|
||||||
return node
|
return node
|
||||||
end
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# Removes the current node from the owning node set.
|
||||||
|
#
|
||||||
|
# @return [Oga::XML::Node]
|
||||||
|
#
|
||||||
|
def remove
|
||||||
|
return node_set.delete(self) if node_set
|
||||||
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
# Generates the inspect value for the current node. Sub classes can
|
# Generates the inspect value for the current node. Sub classes can
|
||||||
# overwrite the {#extra_inspect_data} method to customize the output
|
# overwrite the {#extra_inspect_data} method to customize the output
|
||||||
|
|
|
@ -154,4 +154,24 @@ describe Oga::XML::Node do
|
||||||
@n4.root_node.should == @n3
|
@n4.root_node.should == @n3
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context '#remove' do
|
||||||
|
before do
|
||||||
|
owner = described_class.new
|
||||||
|
@n1 = described_class.new
|
||||||
|
@set = Oga::XML::NodeSet.new([@n1], owner)
|
||||||
|
end
|
||||||
|
|
||||||
|
example 'return a node from the node set' do
|
||||||
|
@n1.remove
|
||||||
|
|
||||||
|
@set.empty?.should == true
|
||||||
|
end
|
||||||
|
|
||||||
|
example 'remove the reference to the set' do
|
||||||
|
@n1.remove
|
||||||
|
|
||||||
|
@n1.node_set.nil?.should == true
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue