Class TreeWalkers::TreeWalker
In: lib/webgen/plugins/miscplugins/treewalker.rb
Parent: Webgen::Plugin
Webgen::Plugin DebugTreePrinter TreeWalker lib/webgen/plugins/miscplugins/treewalker.rb TreeWalkers dot/m_54_0.png

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.

Methods

execute   new   walk_tree  

Attributes

walkers  [R] 

Public Class methods

[Source]

    # File lib/webgen/plugins/miscplugins/treewalker.rb, line 38
38:     def initialize( plugin_manager )
39:       super
40:       @walkers = []
41:     end

Public Instance methods

Walks the tree for the walker in the direction, either +:forward+ or +:backward+. If walker is nil, then all registered walkers are used!

[Source]

    # 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

Private Instance methods

Walks the tree and calls the plugin walker for each and every node.

[Source]

    # 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

[Validate]