Indexing of NodeSet instances.
Similar to arrays the NodeSet class now allows one to retrieve nodes for a given index.
This commit is contained in:
parent
253575dc37
commit
e71fe3d6fa
|
@ -103,6 +103,16 @@ module Oga
|
||||||
return @nodes.pop
|
return @nodes.pop
|
||||||
end
|
end
|
||||||
|
|
||||||
|
##
|
||||||
|
# Returns the node for the given index.
|
||||||
|
#
|
||||||
|
# @param [Fixnum] index
|
||||||
|
# @return [Oga::XML::Node]
|
||||||
|
#
|
||||||
|
def [](index)
|
||||||
|
return @nodes[index]
|
||||||
|
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.
|
||||||
|
|
|
@ -128,6 +128,17 @@ describe Oga::XML::NodeSet do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context '#[]' do
|
||||||
|
before do
|
||||||
|
@n1 = Oga::XML::Element.new(:name => 'a')
|
||||||
|
@set = described_class.new([@n1])
|
||||||
|
end
|
||||||
|
|
||||||
|
example 'return a node from a given index' do
|
||||||
|
@set[0].should == @n1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context '#remove' do
|
context '#remove' do
|
||||||
before do
|
before do
|
||||||
@n1 = Oga::XML::Element.new(:name => 'a')
|
@n1 = Oga::XML::Element.new(:name => 'a')
|
||||||
|
|
Loading…
Reference in New Issue