Class: PointRb::LayoutTree
- Inherits:
-
Object
- Object
- PointRb::LayoutTree
- Defined in:
- lib/pointrb/layout_tree.rb
Instance Attribute Summary collapse
-
#active_node ⇒ Object
readonly
Returns the value of attribute active_node.
-
#tree ⇒ Object
readonly
Returns the value of attribute tree.
Instance Method Summary collapse
- #add_node(node) ⇒ Object
-
#initialize(root_node) ⇒ LayoutTree
constructor
A new instance of LayoutTree.
- #serialize(&block) ⇒ Object
- #up ⇒ Object
Constructor Details
#initialize(root_node) ⇒ LayoutTree
Returns a new instance of LayoutTree.
7 8 9 10 11 12 |
# File 'lib/pointrb/layout_tree.rb', line 7 def initialize(root_node) @counter = -1 @tree = Tree::TreeNode.new(node_id, root_node) @active_node = @tree @prng = Random.new end |
Instance Attribute Details
#active_node ⇒ Object (readonly)
Returns the value of attribute active_node.
5 6 7 |
# File 'lib/pointrb/layout_tree.rb', line 5 def active_node @active_node end |
#tree ⇒ Object (readonly)
Returns the value of attribute tree.
5 6 7 |
# File 'lib/pointrb/layout_tree.rb', line 5 def tree @tree end |
Instance Method Details
#add_node(node) ⇒ Object
14 15 16 17 18 |
# File 'lib/pointrb/layout_tree.rb', line 14 def add_node(node) node = Tree::TreeNode.new(node_id, node) @active_node << node @active_node = node end |
#serialize(&block) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/pointrb/layout_tree.rb', line 24 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 |
#up ⇒ Object
20 21 22 |
# File 'lib/pointrb/layout_tree.rb', line 20 def up @active_node = @active_node.parent end |