Class: KeynoteDriver::TimeCode

Inherits:
Object
  • Object
show all
Defined in:
lib/keynote_driver/time_code.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(timecode_path, delay = 0.0) ⇒ TimeCode

Returns a new instance of TimeCode.



7
8
9
10
11
12
13
14
# File 'lib/keynote_driver/time_code.rb', line 7

def initialize(timecode_path, delay = 0.0)
  if not File.exists?(timecode_path)
    raise TimeCodeException.new "#{timecode_path} doesn't exists."
  end

  @delay = delay
  @timecodes = process(File.read(timecode_path))
end

Instance Attribute Details

#timecodesObject (readonly)

Returns the value of attribute timecodes.



5
6
7
# File 'lib/keynote_driver/time_code.rb', line 5

def timecodes
  @timecodes
end

Instance Method Details

#deltasObject



30
31
32
33
34
35
36
37
38
# File 'lib/keynote_driver/time_code.rb', line 30

def deltas
  timecodes.each_with_index.map do |t, i|
    if i == 0
      t
    else
      t - timecodes[i - 1]
    end
  end
end

#process(timecode) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/keynote_driver/time_code.rb', line 16

def process(timecode)
  lines = timecode.split("\r")
  codes = lines.map{ |l| l.split("\t")[1] }

  out = codes.map{ |c| c.to_f.round(3) + @delay }

  # Check if are not incremental
  if out.sort != out
    raise TimeCodeException.new('Time codes must be incremental.')
  end

  out
end