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.



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

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
29
30
31
32
33
34
# File 'lib/test/unit/xml/nodeiterator.rb', line 17

def NodeIterator.find_next_node(node, node_filter = NullNodeFilter.new)
  #puts "In NodeIterator: #{node.class}"
  #puts "  has_children: #{NodeIterator.has_children?(node)}"
  #puts "  next_sibling_node: #{node.next_sibling_node}"
  #puts "  has_parent_with_sibling?: #{NodeIterator.has_parent_with_sibling?(node)}"
  #node.write if node.respond_to?(:name) && node.name == 'TestThing'
  return nil unless node
  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



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

def has_next()
  @next_node ? true : false
end

#nextObject



46
47
48
49
50
# File 'lib/test/unit/xml/nodeiterator.rb', line 46

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