class TEF::Sequencing::OffsetCollector

Purely internal class

Used by {BaseSequence} when fetching the next event from child sequences. It wraps {EventCollector} and automatically applies a sequence's offset and slope, converting between the timeframe of the parent and the child.

This collector is created in the child, within {BaseSequence#append_events}

Attributes

parent[R]

@return [EventCollector] Top-Level collector

total_offset[R]

@return [Time] Offset of the conversion. Used as follows:

local_time = (Time.at(x) - total_offset) * total_slope
total_slope[R]

@return [Numeric] Slope of the time conversion. @see total_offset

Public Class Methods

new(parent, total_offset, total_slope) click to toggle source

Initialize a new offset collector. This should only be done via {EventCollector#offset_collector}!

# File lib/tef/Sequencing/EventCollector.rb, line 42
def initialize(parent, total_offset, total_slope)
        @parent = parent

        @total_offset = total_offset
        @total_slope  = total_slope.to_f
end

Public Instance Methods

add_event(event) click to toggle source

(see EventCollector#add_event)

# File lib/tef/Sequencing/EventCollector.rb, line 82
def add_event(event)
        event = event.clone

        event[:time] = convert_to_global event[:time]

        @parent.add_event event
end
add_events(list) click to toggle source

(see EventCollector#add_events)

# File lib/tef/Sequencing/EventCollector.rb, line 91
def add_events(list)
        list.each { |event| add_event event }
end
convert_to_global(local_time) click to toggle source

@param [Numeric, nil] local_time Time (abstract) to convert back

into the global frame.

@return [Time, nil] Time (as Time object) of the event

# File lib/tef/Sequencing/EventCollector.rb, line 60
def convert_to_global(local_time)
        return nil if local_time.nil?

        @total_offset + (local_time.to_f.round(3) / @total_slope)
end
convert_to_local(global_time) click to toggle source

@param [Time, nil] global_time Time to convert @return [Numeric, nil] Converted time

# File lib/tef/Sequencing/EventCollector.rb, line 51
def convert_to_local(global_time)
        return nil if global_time.nil?

        ((global_time - @total_offset) * @total_slope).round(3)
end
event_time() click to toggle source

(see EventCollector#event_time)

# File lib/tef/Sequencing/EventCollector.rb, line 72
def event_time
        convert_to_local @parent.event_time
end
has_events?() click to toggle source

(see EventCollector#has_events?)

# File lib/tef/Sequencing/EventCollector.rb, line 77
def has_events?
        return @parent.has_events?
end
offset_collector(offset, slope) click to toggle source

(see EventCollector#offset_collector)

# File lib/tef/Sequencing/EventCollector.rb, line 96
def offset_collector(offset, slope)
        OffsetCollector.new(@parent, convert_to_global(offset), @total_slope * slope)
end
start_time() click to toggle source

(see EventCollector#start_time)

# File lib/tef/Sequencing/EventCollector.rb, line 67
def start_time
        convert_to_local @parent.start_time
end