Don't yield indexes in Document#each_node.
These indexes won't be used so there's no point in yielding them.
This commit is contained in:
parent
4dc85df4e7
commit
ef1ad5406a
|
@ -54,7 +54,7 @@ module Oga
|
|||
# block.
|
||||
#
|
||||
# @example
|
||||
# document.each_node do |node, index|
|
||||
# document.each_node do |node|
|
||||
# p node.class
|
||||
# end
|
||||
#
|
||||
|
@ -63,18 +63,14 @@ module Oga
|
|||
# http://en.wikipedia.org/wiki/Breadth-first_search for more information.
|
||||
#
|
||||
# @yieldparam [Oga::XML::Node] The current node.
|
||||
# @yieldparam [Fixnum] The current node's index.
|
||||
#
|
||||
def each_node
|
||||
visit = children.to_a.dup # copy it since we're modifying the array
|
||||
index = 0
|
||||
|
||||
until visit.empty?
|
||||
current = visit.shift
|
||||
|
||||
yield current, index
|
||||
|
||||
index += 1
|
||||
yield current
|
||||
|
||||
visit = current.children.to_a + visit
|
||||
end
|
||||
|
|
|
@ -53,14 +53,6 @@ describe Oga::XML::Document do
|
|||
|
||||
names.should == %w{books book1 title1 Foo book2 title2 Bar}
|
||||
end
|
||||
|
||||
example 'yield the document indexes' do
|
||||
indexes = []
|
||||
|
||||
@document.each_node { |_, index| indexes << index }
|
||||
|
||||
indexes.should == [0, 1, 2, 3, 4, 5, 6]
|
||||
end
|
||||
end
|
||||
|
||||
context '#to_xml' do
|
||||
|
|
Loading…
Reference in New Issue