lib/tree_graph.rb in tree_graph-0.2.1 vs lib/tree_graph.rb in tree_graph-0.2.2

- old
+ new

@@ -8,29 +8,35 @@ def tree_graph_bottom_up BottomUp.new(self).tree_graph end + def tree_graph_bottom_up_in_same_order + BottomUpInSameOrder.new(self).tree_graph + end + module Node attr_accessor :is_last attr_reader :raw_node, :parent def initialize raw_node, parent=nil @raw_node, @parent, @is_last = raw_node, parent, false end def children_nodes - children = [] - raw_node.children_for_tree_graph.each do |c| - children << self.class.new(c, self) + children.map do |c| + self.class.new(c, self) + end.tap do |nodes| + nodes.last.is_last = true unless nodes.empty? end - return children if children.empty? - children.last.is_last = true - children end + def children + raw_node.children_for_tree_graph + end + def level [indent, branch, raw_node.label_for_tree_graph].join end def levels @@ -75,8 +81,14 @@ end def branch return '' unless parent is_last ? '┌─' : '├─' + end + end + + class BottomUpInSameOrder < BottomUp + def children + super.reverse end end end