Class: SubtitleParser

Inherits:
Object
  • Object
show all
Defined in:
lib/subtitle_parser.rb

Defined Under Namespace

Classes: Subtitle

Instance Method Summary collapse

Instance Method Details

#parse(content) ⇒ Object



3
4
5
6
7
8
9
10
11
12
# File 'lib/subtitle_parser.rb', line 3

def parse content
  subs = []
  unless content.empty?
    content.scan(/^(?<order>(\d{1,4}))\n(?<begins>.+)\s*-->\s*(?<ends>.+)\n(?<sentences>(.+\n)*)/) do |order, begins, ends, sentence|
      subs << Subtitle.new(order, begins, ends, sentence.gsub("\n", ""))
    end
  end
    
  return subs
end