Sha256: 98e40da30c44bf064ab599169f9cb84823bb5261e95d5f4b7b8df1777e41be3a

Contents?: true

Size: 976 Bytes

Versions: 33

Compression:

Stored size: 976 Bytes

Contents

module Shelr
  class TTYRec

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

    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

    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
  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
shelr-0.16.3 lib/shelr/ttyrec.rb
shelr-0.16.2 lib/shelr/ttyrec.rb
shelr-0.16.1 lib/shelr/ttyrec.rb
shelr-0.16.0 lib/shelr/ttyrec.rb
shelr-0.15.2 lib/shelr/ttyrec.rb
shelr-0.15.1 lib/shelr/ttyrec.rb
shelr-0.15.0 lib/shelr/ttyrec.rb
shelr-0.14.1 lib/shelr/ttyrec.rb
shelr-0.14.0 lib/shelr/ttyrec.rb
shelr-0.13.3 lib/shelr/ttyrec.rb
shelr-0.13.2 lib/shelr/ttyrec.rb
shelr-0.13.1 lib/shelr/ttyrec.rb
shelr-0.13.0 lib/shelr/ttyrec.rb
shelr-0.12.9 lib/shelr/ttyrec.rb
shelr-0.12.8 lib/shelr/ttyrec.rb
shelr-0.12.7 lib/shelr/ttyrec.rb
shelr-0.12.6 lib/shelr/ttyrec.rb
shelr-0.12.5 lib/shelr/ttyrec.rb
shelr-0.12.4 lib/shelr/ttyrec.rb
shelr-0.12.3 lib/shelr/ttyrec.rb