Class: SplitCommand

Inherits:
Clamp::Command
  • Object
show all
Defined in:
lib/commands/split_command.rb

Instance Method Summary collapse

Instance Method Details

#executeObject



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/commands/split_command.rb', line 14

def execute
  file = File.open(path)
  srt = SRT::File.parse(file)
  results = srt.split(every: interval, renumber: renumber?)
  progress = ProgressBar.create(title: 'Saving subtitle', starting_at: 0, total: results.length)

  results.each_with_index do |line, index|
    File.write("#{output_dir}/#{prefix}-#{'%03d' % (starting_index.to_i+index)}.srt", line.to_s)
    progress.increment
  end
end