Class: TreeRb::CallbackTreeNodeVisitor2
- Inherits:
-
Object
- Object
- TreeRb::CallbackTreeNodeVisitor2
- Defined in:
- lib/tree_rb/visitors/callback_tree_node_visitor2.rb
Overview
Executes a block when enter in a node The block are defined from on_enter_X methods The blocks take as argument the node and the parent_node
Instance Attribute Summary collapse
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Instance Method Summary collapse
-
#cannot_enter_node(tree_node, error) ⇒ Object
called when the tree node is not accessible or an exception is raise when the node is accessed.
- #enter_node(src_tree_node) ⇒ Object
- #exit_node(src_tree_node) ⇒ Object
-
#initialize(delegate = nil) ⇒ CallbackTreeNodeVisitor2
constructor
A new instance of CallbackTreeNodeVisitor2.
- #on_enter_node(&block) ⇒ Object
- #on_visit_leaf(&block) ⇒ Object
- #visit_leaf(src_leaf_node) ⇒ Object
Constructor Details
#initialize(delegate = nil) ⇒ CallbackTreeNodeVisitor2
Returns a new instance of CallbackTreeNodeVisitor2.
12 13 14 15 16 |
# File 'lib/tree_rb/visitors/callback_tree_node_visitor2.rb', line 12 def initialize(delegate = nil) @stack = [] @root = nil @delegate = delegate end |
Instance Attribute Details
#root ⇒ Object (readonly)
Returns the value of attribute root.
10 11 12 |
# File 'lib/tree_rb/visitors/callback_tree_node_visitor2.rb', line 10 def root @root end |
Instance Method Details
#cannot_enter_node(tree_node, error) ⇒ Object
called when the tree node is not accessible or an exception is raise when the node is accessed
43 44 |
# File 'lib/tree_rb/visitors/callback_tree_node_visitor2.rb', line 43 def cannot_enter_node( tree_node, error) end |
#enter_node(src_tree_node) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/tree_rb/visitors/callback_tree_node_visitor2.rb', line 28 def enter_node(src_tree_node) dst_parent_node = @stack.empty? ? nil : @stack.last dst_tree_node = @action_enter_tree_node.call(src_tree_node, dst_parent_node) if @action_enter_tree_node dst_tree_node = @delegate.enter_node(src_tree_node, dst_parent_node) if @delegate and @delegate.respond_to? :enter_node @root = dst_tree_node if @stack.empty? @stack.push(dst_tree_node) end |
#exit_node(src_tree_node) ⇒ Object
36 37 38 |
# File 'lib/tree_rb/visitors/callback_tree_node_visitor2.rb', line 36 def exit_node(src_tree_node) @stack.pop end |
#on_enter_node(&block) ⇒ Object
18 19 20 21 |
# File 'lib/tree_rb/visitors/callback_tree_node_visitor2.rb', line 18 def on_enter_node(&block) raise 'already defined a delegate' if @delegate @action_enter_tree_node = block end |
#on_visit_leaf(&block) ⇒ Object
23 24 25 26 |
# File 'lib/tree_rb/visitors/callback_tree_node_visitor2.rb', line 23 def on_visit_leaf(&block) raise 'already defined a delegate' if @delegate @action_visit_leaf_node = block end |
#visit_leaf(src_leaf_node) ⇒ Object
46 47 48 49 50 |
# File 'lib/tree_rb/visitors/callback_tree_node_visitor2.rb', line 46 def visit_leaf(src_leaf_node) parent_node = @stack.last @action_visit_leaf_node.call(src_leaf_node, parent_node) if @action_visit_leaf_node @delegate.visit_leaf(src_leaf_node, parent_node) if @delegate and @delegate.respond_to? :visit_leaf end |