module TreeGraph::Node

Attributes

is_last[RW]
parent[R]
raw_node[R]

Public Class Methods

new(raw_node, parent=nil) click to toggle source
# File lib/tree_graph.rb, line 22
def initialize raw_node, parent=nil
  @raw_node, @parent, @is_last = raw_node, parent, false
end

Public Instance Methods

ancestors() click to toggle source
# File lib/tree_graph.rb, line 46
def ancestors
  return [] unless parent
  parent.ancestors + [parent]
end
children() click to toggle source
# File lib/tree_graph.rb, line 34
def children
  raw_node.children_for_tree_graph
end
children_nodes() click to toggle source
# File lib/tree_graph.rb, line 26
def children_nodes
  children.map do |c|
    self.class.new(c, self)
  end.tap do |nodes|
    nodes.last.is_last = true unless nodes.empty?
  end
end
indent() click to toggle source
# File lib/tree_graph.rb, line 51
def indent
  ancestors.map do |a|
    unless a.parent
      ''
    else
      a.is_last ? '  ' : '│ '
    end
  end.join
end
level() click to toggle source
# File lib/tree_graph.rb, line 38
def level
  [indent, branch, raw_node.label_for_tree_graph].join
end
levels() click to toggle source
# File lib/tree_graph.rb, line 42
def levels
  [level] + children_nodes.map(&:tree_graph)
end