Class: Shelr::TTYRec

Inherits:
Object
  • Object
show all
Defined in:
lib/shelr/ttyrec.rb

Instance Method Summary collapse

Constructor Details

#initialize(ttyrec) ⇒ TTYRec

Returns a new instance of TTYRec.



4
5
6
7
# File 'lib/shelr/ttyrec.rb', line 4

def initialize(ttyrec)
  @io = ttyrec
  @timeline = []
end

Instance Method Details

#parseObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/shelr/ttyrec.rb', line 9

def parse
  while !@io.eof?
    frame = {}
    
    sec, usec, len = @io.read(12).unpack('VVV')
    data = @io.read(len)
    
    prev_timestamp ||= [ sec, usec ].join('.').to_f
    curr_timestamp   = [ sec, usec ].join('.').to_f
    
    offset = curr_timestamp - prev_timestamp

    frame = {
      :offset => "%5.6f" % offset,
      :data   => data,
      :length => len
    }
    
    @timeline << frame

    prev_timestamp = curr_timestamp
    prev_data = data
  end
  
  self
end

#to_typescriptObject



36
37
38
39
40
41
42
43
44
45
# File 'lib/shelr/ttyrec.rb', line 36

def to_typescript
  script = { :typescript => "Script started...\n", :timing => "" }

  @timeline.each do |frame|
    script[:timing] += [frame[:offset], ' ', frame[:length], "\n"].join
    script[:typescript] += frame[:data]
  end

  script
end