I'm trying to create objects from each recurring set in the text below (an .srt subtitle file):
1
00:02:12,446 --> 00:02:14,406
The Hovitos are near.
2
00:02:15,740 --> 00:02:18,076
The poison is still fresh,
three days.
3
00:02:18,076 --> 00:02:19,744
They're following us.
For example, I could take the three or four lines and assign them to attributes of the new object. So for the first set, I could have Sentence.create(number: 1, time_marker: '00:02:12', content: "The Hovitos are near.")
Start with script.each_line, and what other general structure might put me on the right track? I'm having a hard time with this and any help would be fantastic!
Edit
Some of the messy unfinished code I have so far is below. It actually works (I think). Would you have taken a totally different route? I don't have any experience with this.
number = nil
time_marker = nil
content = []
script = script.strip
script.each_line do |line|
line = line.strip
if line =~ /^\d+$/
number = line.to_i
elsif line =~ /-->/
time_marker = line[0..7]
elsif line =~ /^\b\D/
content << line
else
if content.size > 1
content = content.join("\n")
else
content = content[0]
end
Sentence.create(movie: @movie, number: number,
time_marker: time_marker, content: content)
content = []
end
end