Class: SSRT
- Inherits:
-
Object
- Object
- SSRT
- Defined in:
- lib/ssrt.rb
Constant Summary collapse
- VERSION =
"0.1.0"
- TIMESTAMP_PATTERN =
/\d\d:\d\d:\d{4}/
Class Method Summary collapse
Class Method Details
.ssrt2srt(file) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/ssrt.rb', line 5 def self.ssrt2srt(file) str=file.read new_buf = ['00:00:0000'] str.each_line.with_index do |l, i| time_start = new_buf[i-1].scan(TIMESTAMP_PATTERN).last time_end, text = l.split[0], l.split[1..].join(' ') new_buf[i] = "#{i+1}\n#{time_start} --> #{time_end}\n#{text}\n\n" end new_str = new_buf.join.strip end |