#encoding: utf-8 module PointRb class LayoutTree attr_reader :tree, :active_node def initialize(root_node) @counter = -1 @tree = Tree::TreeNode.new(node_id, root_node) @active_node = @tree @prng = Random.new end def add_node(node) node = Tree::TreeNode.new(node_id, node) @active_node << node @active_node = node end def up @active_node = @active_node.parent end def serialize(&block) serialized_tree = [] #default action during serialize block = lambda { |node| node.content } unless block @tree.each do |node| serialized_tree << block.call(node) end serialized_tree end private def node_id @counter += 1 "node#{@counter}" end end end