Class: Stdout::Buffered

Inherits:
Stdout
  • Object
show all
Defined in:
lib/asciinema/stdout.rb

Constant Summary collapse

MIN_FRAME_LENGTH =
1.0 / 60

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stdout) ⇒ Buffered

Returns a new instance of Buffered.



78
79
80
# File 'lib/asciinema/stdout.rb', line 78

def initialize(stdout)
  @stdout = stdout
end

Instance Attribute Details

#stdoutObject (readonly)

Returns the value of attribute stdout.



76
77
78
# File 'lib/asciinema/stdout.rb', line 76

def stdout
  @stdout
end

Instance Method Details

#each {|buffered_delay, buffered_data.join| ... } ⇒ Object

Yields:

  • (buffered_delay, buffered_data.join)


82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/asciinema/stdout.rb', line 82

def each
  buffered_delay, buffered_data = 0.0, []

  stdout.each do |delay, data|
    if buffered_delay + delay < MIN_FRAME_LENGTH || buffered_data.empty?
      buffered_delay += delay
      buffered_data << data
    else
      yield(buffered_delay, buffered_data.join)
      buffered_delay = delay
      buffered_data = [data]
    end
  end

  yield(buffered_delay, buffered_data.join) unless buffered_data.empty?
end