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
@return [EventCollector] Top-Level collector
@return [Time] Offset of the conversion. Used as follows:
local_time = (Time.at(x) - total_offset) * total_slope
@return [Numeric] Slope of the time conversion. @see total_offset
Public Class Methods
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
(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
(see EventCollector#add_events)
# File lib/tef/Sequencing/EventCollector.rb, line 91 def add_events(list) list.each { |event| add_event event } end
@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
@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
(see EventCollector#event_time
)
# File lib/tef/Sequencing/EventCollector.rb, line 72 def event_time convert_to_local @parent.event_time end
(see EventCollector#has_events?
)
# File lib/tef/Sequencing/EventCollector.rb, line 77 def has_events? return @parent.has_events? end
(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
(see EventCollector#start_time
)
# File lib/tef/Sequencing/EventCollector.rb, line 67 def start_time convert_to_local @parent.start_time end