class TRecs::TrecsFileStrategy
Attributes
frames[R]
from[R]
input_file[R]
speed[R]
timestamps[R]
to[R]
Public Class Methods
new(options={})
click to toggle source
# File lib/trecs/strategies/trecs_file_strategy.rb, line 15 def initialize(options={}) @input_file = options.fetch(:input_file) source = TRecs::TgzSource.new(trecs_backend: input_file) @frames = get_frames(source) @from = options.fetch(:from) { 0 } @from = (@from || 0).to_i @to = options.fetch(:to) { nil } @to = @to.to_i if @to @speed = options.fetch(:speed) { 1.0 } @speed = @speed.to_f end
Public Instance Methods
perform()
click to toggle source
# File lib/trecs/strategies/trecs_file_strategy.rb, line 31 def perform timestamps.each do |time| current_time(((time-from)/speed.to_f).to_i) current_content(frames[time]) current_format(frames[time].format) save_frame if current_content end end
Private Instance Methods
get_frames(source)
click to toggle source
# File lib/trecs/strategies/trecs_file_strategy.rb, line 55 def get_frames(source) frames = {} source.read do json_string = source.read_entry("frames.json") || "{}" parsed_json = JSON.parse(json_string, symbolize_names: true) parsed_json.each do |time, value| frames[Integer(time.to_s)] = Frame(value) end end frames end