Class: CallbackTreeNodeVisitor

Inherits:
TreeNodeVisitor show all
Defined in:
lib/tree_visitor/tree_node_visitor.rb

Overview

CallbackTreeNodeVisitor

Instance Method Summary collapse

Constructor Details

#initialize(root = nil) ⇒ CallbackTreeNodeVisitor

Returns a new instance of CallbackTreeNodeVisitor.



168
169
170
171
172
173
174
175
# File 'lib/tree_visitor/tree_node_visitor.rb', line 168

def initialize( root = nil )
  super()
  @stack = []
  @root = root
  @stack.push( root ) if root
  @action_enterTreeNode = nil
  @action_visitLeafNode = nil
end

Instance Method Details

#enter_treeNode(treeNode) ⇒ Object



185
186
187
188
189
190
191
192
193
194
# File 'lib/tree_visitor/tree_node_visitor.rb', line 185

def enter_treeNode( treeNode )
  parentNode = if @stack.empty? 
                 nil
               else
                 @stack.last
               end
  @root = treeNode if @stack.empty?
  @stack.push( treeNode ) 
  @action_enterTreeNode.call( treeNode ) if @action_enterTreeNode
end

#exit_treeNode(treeNode) ⇒ Object



196
197
198
# File 'lib/tree_visitor/tree_node_visitor.rb', line 196

def exit_treeNode( treeNode )
  @stack.pop
end

#onEnterTreeNode(&action) ⇒ Object



177
178
179
# File 'lib/tree_visitor/tree_node_visitor.rb', line 177

def onEnterTreeNode( &action )
  @action_enterTreeNode = action
end

#onVisitLeafNode(&action) ⇒ Object



181
182
183
# File 'lib/tree_visitor/tree_node_visitor.rb', line 181

def onVisitLeafNode( &action )
  @action_visitLeafNode = action
end

#visit_leafNode(leafNode) ⇒ Object



200
201
202
203
# File 'lib/tree_visitor/tree_node_visitor.rb', line 200

def visit_leafNode( leafNode )
  parentNode = @stack.last
  @action_visitLeafNode.call( leafNode ) if @action_visitLeafNode
end