Class: Supertitle::Read::Srt

Inherits:
Object
  • Object
show all
Defined in:
lib/supertitle/read/srt.rb

Instance Method Summary collapse

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

#readObject



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