Module: TreeGraph::Node
Instance Attribute Summary collapse
-
#is_last ⇒ Object
Returns the value of attribute is_last.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#raw_node ⇒ Object
readonly
Returns the value of attribute raw_node.
Instance Method Summary collapse
- #ancestors ⇒ Object
- #children ⇒ Object
- #children_nodes ⇒ Object
- #indent ⇒ Object
- #initialize(raw_node, parent = nil) ⇒ Object
- #level ⇒ Object
- #levels ⇒ Object
Instance Attribute Details
#is_last ⇒ Object
Returns the value of attribute is_last.
31 32 33 |
# File 'lib/tree_graph.rb', line 31 def is_last @is_last end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
32 33 34 |
# File 'lib/tree_graph.rb', line 32 def parent @parent end |
#raw_node ⇒ Object (readonly)
Returns the value of attribute raw_node.
32 33 34 |
# File 'lib/tree_graph.rb', line 32 def raw_node @raw_node end |
Instance Method Details
#ancestors ⇒ Object
58 59 60 61 |
# File 'lib/tree_graph.rb', line 58 def ancestors return EMPTY_ARRAY unless parent parent.ancestors + [parent] end |
#children ⇒ Object
46 47 48 |
# File 'lib/tree_graph.rb', line 46 def children raw_node.children_for_tree_graph end |
#children_nodes ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/tree_graph.rb', line 38 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 ⇒ Object
63 64 65 66 67 68 69 70 71 |
# File 'lib/tree_graph.rb', line 63 def indent ancestors.map do |a| unless a.parent '' else a.is_last ? ' ' : '│ ' end end.join end |
#initialize(raw_node, parent = nil) ⇒ Object
34 35 36 |
# File 'lib/tree_graph.rb', line 34 def initialize raw_node, parent=nil @raw_node, @parent, @is_last = raw_node, parent, false end |
#level ⇒ Object
50 51 52 |
# File 'lib/tree_graph.rb', line 50 def level [indent, branch, raw_node.label_for_tree_graph].join end |
#levels ⇒ Object
54 55 56 |
# File 'lib/tree_graph.rb', line 54 def levels [level] + children_nodes.map(&:tree_graph) end |