class Shelr::TTYRec

Public Class Methods

new(ttyrec) click to toggle source
# File lib/shelr/ttyrec.rb, line 4
def initialize(ttyrec)
  @io = ttyrec
  @timeline = []
end

Public Instance Methods

parse() click to toggle source
# 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_typescript() click to toggle source
# 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