Class: Supertitle::Read::Srt
- Inherits:
-
Object
- Object
- Supertitle::Read::Srt
- Defined in:
- lib/supertitle/read/srt.rb
Instance Method Summary collapse
-
#initialize(content) ⇒ Srt
constructor
A new instance of Srt.
- #read ⇒ Object
Constructor Details
#initialize(content) ⇒ Srt
Returns a new instance of Srt.
5 6 7 |
# File 'lib/supertitle/read/srt.rb', line 5 def initialize(content) @content = content end |
Instance Method Details
#read ⇒ Object
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/supertitle/read/srt.rb', line 9 def read @content. split(/\r\n|\n/). chunk { |line| line == "" }. #<- group by every blank line reject { |(blank,_)| blank }. #<- eliminate blank lines map { |(_, components)| start, stop = time_offsets_for(components[1]) Supertitle::Line.new(start, stop, components[2..-1].map(&:strip).join(" ")) } end |