Class: Sjson2srt::Converter
- Inherits:
-
Object
- Object
- Sjson2srt::Converter
- Defined in:
- lib/sjson2srt/converter.rb
Instance Method Summary collapse
- #convert ⇒ Object
-
#initialize(content) ⇒ Converter
constructor
A new instance of Converter.
Constructor Details
#initialize(content) ⇒ Converter
Returns a new instance of Converter.
4 5 6 |
# File 'lib/sjson2srt/converter.rb', line 4 def initialize(content) @json = JSON.parse(content) end |
Instance Method Details
#convert ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/sjson2srt/converter.rb', line 8 def convert output = [] json['text'].each_with_index do |line, i| start_time = json['start'][i] end_time = json['end'][i] output << i + 1 output << "#{format_time(start_time)} --> #{format_time(end_time)}" if line.length > 0 output << "#{line}\n" else output << '' end end output.join("\n") end |