class TRecs::Player

Attributes

current_time[RW]
prev_content[RW]
reader[R]
screen[R]
step[R]
testing[R]
ticker[R]

Public Class Methods

new(options={}) click to toggle source
# File lib/trecs/player.rb, line 11
def initialize(options={})
  time = options.fetch(:time) { nil }
  @reader        = options.fetch(:reader)
  @reader.player = self

  @ticker        = options.fetch(:ticker)
  @ticker.player = self

  @screen       = options.fetch(:screen) { TerminalScreen.new }

  @testing      = options.fetch(:testing) { false }

  @current_time = time
  @step         = options.fetch(:step) { 100 }
end

Public Instance Methods

play() click to toggle source
# File lib/trecs/player.rb, line 27
def play
  reader.setup
  ticker.start
end
tick(time=current_time) click to toggle source
# File lib/trecs/player.rb, line 32
def tick(time=current_time)
  content = reader.frame_at(time_to_play(time))
  if content != prev_content
    screen.clear
    screen.puts(content.to_s)
    self.prev_content = content
  end
  content
end
time_to_play(time) click to toggle source
# File lib/trecs/player.rb, line 46
def time_to_play(time)
  timestamps.reverse.detect { |t| t <= time.to_i  }
end
timestamps() click to toggle source
# File lib/trecs/player.rb, line 42
def timestamps
  @timestamps ||= reader.timestamps.sort
end