| Class | TreeWalkers::TreeWalker |
| In: |
lib/webgen/plugins/miscplugins/treewalker.rb
|
| Parent: | Webgen::Plugin |
This is the main class for tree walkers. A tree walker plugin can register itself with this class so that it is called when the main class’ execute method is called.
| walkers | [R] |
# File lib/webgen/plugins/miscplugins/treewalker.rb, line 38
38: def initialize( plugin_manager )
39: super
40: @walkers = []
41: end
Walks the tree for the walker in the direction, either +:forward+ or +:backward+. If walker is nil, then all registered walkers are used!
# File lib/webgen/plugins/miscplugins/treewalker.rb, line 45
45: def execute( tree, walker = nil, direction = :forward )
46: walkers = ( walker.nil? ? @walkers : [walker] )
47: walkers.each do |walker|
48: walk_tree( tree, walker, 0, direction )
49: end
50: end
Walks the tree and calls the plugin walker for each and every node.
# File lib/webgen/plugins/miscplugins/treewalker.rb, line 57
57: def walk_tree( node, walker, level, direction = :forward )
58: walker.call( node, level ) if direction == :forward
59: node.each do |child|
60: walk_tree( child, walker, level + 1, direction )
61: end
62: walker.call( node, level ) if direction == :backward
63: end