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.
19 20 21 |
# File 'lib/tree_graph.rb', line 19 def is_last @is_last end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
20 21 22 |
# File 'lib/tree_graph.rb', line 20 def parent @parent end |
#raw_node ⇒ Object (readonly)
Returns the value of attribute raw_node.
20 21 22 |
# File 'lib/tree_graph.rb', line 20 def raw_node @raw_node end |
Instance Method Details
#ancestors ⇒ Object
46 47 48 49 |
# File 'lib/tree_graph.rb', line 46 def ancestors return [] unless parent parent.ancestors + [parent] end |
#children ⇒ Object
34 35 36 |
# File 'lib/tree_graph.rb', line 34 def children raw_node.children_for_tree_graph end |
#children_nodes ⇒ Object
26 27 28 29 30 31 32 |
# 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 ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/tree_graph.rb', line 51 def indent ancestors.map do |a| unless a.parent '' else a.is_last ? ' ' : '│ ' end end.join end |
#initialize(raw_node, parent = nil) ⇒ Object
22 23 24 |
# File 'lib/tree_graph.rb', line 22 def initialize raw_node, parent=nil @raw_node, @parent, @is_last = raw_node, parent, false end |
#level ⇒ Object
38 39 40 |
# File 'lib/tree_graph.rb', line 38 def level [indent, branch, raw_node.label_for_tree_graph].join end |
#levels ⇒ Object
42 43 44 |
# File 'lib/tree_graph.rb', line 42 def levels [level] + children_nodes.map(&:tree_graph) end |