Class: PrintTreeNodeVisitor2

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

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ PrintTreeNodeVisitor2

Returns a new instance of PrintTreeNodeVisitor2.



3
4
5
6
# File 'lib/tree_visitor/visitor/print_node_visitor2.rb', line 3

def initialize( *args )
  super( *args )
  @depth = 0
end

Instance Method Details

#enter_treeNode(treeNode) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/tree_visitor/visitor/print_node_visitor2.rb', line 17

def enter_treeNode( treeNode )

  str = ""
  (0...@depth).step {
    str << " |-"
  }

  if @depth == 0
    puts str + treeNode.to_s
  else
    puts str + treeNode.to_s
  end
  @depth += 1
end

#exit_treeNode(treeNode) ⇒ Object



32
33
34
# File 'lib/tree_visitor/visitor/print_node_visitor2.rb', line 32

def exit_treeNode( treeNode )
  @depth -= 1
end

#visit_leafNode(leafNode) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/tree_visitor/visitor/print_node_visitor2.rb', line 8

def visit_leafNode( leafNode )
  str = ""
  (0...@depth-1).step {
    str << " |-"
  }
  str << " |  "
  puts str + leafNode.to_s
end