Class: TimeFrame::Collection::TreeNode
- Inherits:
-
Object
- Object
- TimeFrame::Collection::TreeNode
- Defined in:
- lib/time_frame/tree_node.rb
Overview
This is a helper class for the collection. It contains the node definition for the used tree structues.
Instance Attribute Summary collapse
-
#ancestor ⇒ Object
readonly
Returns the value of attribute ancestor.
-
#child_time_frame ⇒ Object
Returns the value of attribute child_time_frame.
-
#item ⇒ Object
readonly
Returns the value of attribute item.
-
#left_child ⇒ Object
Returns the value of attribute left_child.
-
#right_child ⇒ Object
Returns the value of attribute right_child.
-
#time_frame ⇒ Object
readonly
Returns the value of attribute time_frame.
Instance Method Summary collapse
-
#initialize(args, &block) ⇒ TreeNode
constructor
A new instance of TreeNode.
- #update_ancestor_relation(new_ancestor, side) ⇒ Object
- #update_child_frame(new_child_frame) ⇒ Object
Constructor Details
#initialize(args, &block) ⇒ TreeNode
Returns a new instance of TreeNode.
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/time_frame/tree_node.rb', line 9 def initialize(args, &block) @item = args.fetch(:item) @time_frame = block.call(item) # if ancestor is nil, then tree_item is root node @ancestor = args.fetch(:ancestor, nil) @left_child = args.fetch(:left_child, nil) @right_child = args.fetch(:right_child, nil) # if block is given use it to get item's time frame @child_time_frame = @time_frame end |
Instance Attribute Details
#ancestor ⇒ Object (readonly)
Returns the value of attribute ancestor.
8 9 10 |
# File 'lib/time_frame/tree_node.rb', line 8 def ancestor @ancestor end |
#child_time_frame ⇒ Object
Returns the value of attribute child_time_frame.
7 8 9 |
# File 'lib/time_frame/tree_node.rb', line 7 def child_time_frame @child_time_frame end |
#item ⇒ Object (readonly)
Returns the value of attribute item.
8 9 10 |
# File 'lib/time_frame/tree_node.rb', line 8 def item @item end |
#left_child ⇒ Object
Returns the value of attribute left_child.
7 8 9 |
# File 'lib/time_frame/tree_node.rb', line 7 def left_child @left_child end |
#right_child ⇒ Object
Returns the value of attribute right_child.
7 8 9 |
# File 'lib/time_frame/tree_node.rb', line 7 def right_child @right_child end |
#time_frame ⇒ Object (readonly)
Returns the value of attribute time_frame.
8 9 10 |
# File 'lib/time_frame/tree_node.rb', line 8 def time_frame @time_frame end |
Instance Method Details
#update_ancestor_relation(new_ancestor, side) ⇒ Object
21 22 23 24 25 |
# File 'lib/time_frame/tree_node.rb', line 21 def update_ancestor_relation(new_ancestor, side) @ancestor = new_ancestor new_ancestor.left_child = self if side == :left new_ancestor.right_child = self if side == :right end |
#update_child_frame(new_child_frame) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/time_frame/tree_node.rb', line 27 def update_child_frame(new_child_frame) min = [@child_time_frame.min, new_child_frame.min].min max = [@child_time_frame.max, new_child_frame.max].max @child_time_frame = TimeFrame.new(min: min, max: max) ancestor.update_child_frame(@child_time_frame) if ancestor end |