2013-08-04 20:43:36 +00:00
|
|
|
class Stdout
|
|
|
|
include Enumerable
|
|
|
|
|
2013-08-15 18:58:41 +00:00
|
|
|
attr_reader :data_path, :timing_path
|
2013-08-04 20:43:36 +00:00
|
|
|
|
2013-08-15 18:58:41 +00:00
|
|
|
def initialize(data_path, timing_path)
|
|
|
|
@data_path = data_path
|
|
|
|
@timing_path = timing_path
|
2013-08-04 20:43:36 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def each
|
2013-08-15 18:58:41 +00:00
|
|
|
File.open(data_path, 'rb') do |file|
|
|
|
|
File.foreach(timing_path) do |line|
|
2013-08-13 17:27:02 +00:00
|
|
|
delay, size = TimingParser.parse_line(line)
|
|
|
|
yield(delay, file.read(size).force_encoding('utf-8'))
|
|
|
|
end
|
2013-08-04 20:43:36 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-08-13 17:27:02 +00:00
|
|
|
def each_until(seconds)
|
2013-08-04 20:43:36 +00:00
|
|
|
time = 0
|
|
|
|
|
2013-08-13 17:27:02 +00:00
|
|
|
each do |delay, frame_data|
|
2013-08-04 20:43:36 +00:00
|
|
|
time += delay
|
|
|
|
break if time > seconds
|
2013-08-13 17:27:02 +00:00
|
|
|
yield(delay, frame_data)
|
2013-08-04 20:43:36 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|