Class: Test::Unit::XML::NodeIterator

Inherits:
Object
  • Object
show all
Defined in:
lib/test/unit/xml/nodeiterator.rb

Defined Under Namespace

Classes: NullNodeFilter

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node, node_filter = NullNodeFilter.new) ⇒ NodeIterator

Returns a new instance of NodeIterator.



31
32
33
34
# File 'lib/test/unit/xml/nodeiterator.rb', line 31

def initialize(node, node_filter = NullNodeFilter.new)
  @node_filter = node_filter
  @next_node = node
end

Class Method Details

.find_next_node(node, node_filter = NullNodeFilter.new) ⇒ Object

This class method takes a node as an argument and locates the next node. The first argument is a node. The second argument is an optional node filter.



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/test/unit/xml/nodeiterator.rb', line 17

def NodeIterator.find_next_node(node, node_filter = NullNodeFilter.new)
  next_node = nil
  if NodeIterator.has_children?(node) then
    next_node = node[0] # The index should be 1 according to the REXML docs
  elsif node.next_sibling_node
    next_node = node.next_sibling_node
  elsif NodeIterator.has_parent_with_sibling?(node)
    next_node = node.parent.next_sibling_node
  end
  return next_node if node_filter.accept(next_node) || next_node == nil
  find_next_node(next_node, node_filter)
end

Instance Method Details

#has_nextObject



36
37
38
# File 'lib/test/unit/xml/nodeiterator.rb', line 36

def has_next()
  @next_node ? true : false
end

#nextObject



40
41
42
43
44
# File 'lib/test/unit/xml/nodeiterator.rb', line 40

def next
  node = @next_node
  @next_node = NodeIterator.find_next_node(node, @node_filter)
  node
end