Class: PrintTreeNodeVisitor

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

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ PrintTreeNodeVisitor

Returns a new instance of PrintTreeNodeVisitor.



69
70
71
72
# File 'lib/tree_visitor/tree_node_visitor.rb', line 69

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

Instance Method Details

#enter_treeNode(treeNode) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/tree_visitor/tree_node_visitor.rb', line 83

def enter_treeNode( treeNode )

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

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

#exit_treeNode(treeNode) ⇒ Object



98
99
100
# File 'lib/tree_visitor/tree_node_visitor.rb', line 98

def exit_treeNode( treeNode )
  @depth -= 1
end

#visit_leafNode(leafNode) ⇒ Object



74
75
76
77
78
79
80
81
# File 'lib/tree_visitor/tree_node_visitor.rb', line 74

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