Sha256: e5a8c6d64c4994749146a78d2c6af8eb58f948a30befc30fcfac1514c442cd03

Contents?: true

Size: 856 Bytes

Versions: 11

Compression:

Stored size: 856 Bytes

Contents

# -*- coding: utf-8 -*-
module TreeRb
  #
  # Prints TreeNode names indenting according to depth
  #
  class PrintTreeNodeVisitor # < BasicTreeNodeVisitor

    def initialize
      @depth = 0
    end

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

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

    def exit_node( tree_node )
      @depth -= 1
    end

    #
    # called when the tree node is not accessible or an exception is raise when the node is accessed
    #
    def cannot_enter_node( tree_node, error)
    end

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

  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
tree.rb-0.3.11 lib/tree_rb/visitors/print_tree_node_visitor.rb
tree.rb-0.3.10 lib/tree_rb/visitors/print_tree_node_visitor.rb
tree.rb-0.3.9 lib/tree_rb/visitors/print_tree_node_visitor.rb
tree.rb-0.3.8 lib/tree_rb/visitors/print_tree_node_visitor.rb
tree.rb-0.3.7 lib/tree_rb/visitors/print_tree_node_visitor.rb
tree.rb-0.3.6 lib/tree_rb/visitors/print_tree_node_visitor.rb
tree.rb-0.3.5 lib/tree_rb/visitors/print_tree_node_visitor.rb
tree.rb-0.3.4 lib/tree_rb/visitors/print_tree_node_visitor.rb
tree.rb-0.3.3 lib/tree_rb/visitors/print_tree_node_visitor.rb
tree.rb-0.3.2 lib/tree_rb/visitors/print_tree_node_visitor.rb
tree.rb-0.3.1 lib/tree_rb/visitors/print_tree_node_visitor.rb