Class: TreeRb::DepthTreeNodeVisitor

Inherits:
Object
  • Object
show all
Defined in:
lib/tree_rb/visitors/depth_tree_node_visitor.rb

Overview

Simple visitor: show how calculate the depth of a tree

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDepthTreeNodeVisitor

Returns a new instance of DepthTreeNodeVisitor.



10
11
12
# File 'lib/tree_rb/visitors/depth_tree_node_visitor.rb', line 10

def initialize
  @depth = 0
end

Instance Attribute Details

#depthObject (readonly)

< BasicTreeNodeVisitor



8
9
10
# File 'lib/tree_rb/visitors/depth_tree_node_visitor.rb', line 8

def depth
  @depth
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



25
26
# File 'lib/tree_rb/visitors/depth_tree_node_visitor.rb', line 25

def cannot_enter_node( tree_node, error)
end

#enter_node(tree_node) ⇒ Object



14
15
16
# File 'lib/tree_rb/visitors/depth_tree_node_visitor.rb', line 14

def enter_node( tree_node )
  @depth += 1
end

#exit_node(tree_node) ⇒ Object



18
19
20
# File 'lib/tree_rb/visitors/depth_tree_node_visitor.rb', line 18

def exit_node( tree_node )
  @depth -= 1
end

#visit_leaf(leaf_node) ⇒ Object



28
29
# File 'lib/tree_rb/visitors/depth_tree_node_visitor.rb', line 28

def visit_leaf( leaf_node )
end