class TimeFrame::Collection::TreeNode

This is a helper class for the collection. It contains the node definition for the used tree structues.

Attributes

ancestor[R]
child_time_frame[RW]
item[R]
left_child[RW]
right_child[RW]
time_frame[R]

Public Class Methods

new(args, &block) click to toggle source
# 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

Public Instance Methods

update_ancestor_relation(new_ancestor, side) click to toggle source
# 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) click to toggle source
# 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