Method: ASSLine#to_subs_time
- Defined in:
- lib/vtt2ass/ass_line.rb
#to_subs_time(str) ⇒ Object
This method converts time from VTT format to the ASS format.
-
Requires
str, a VTT formatted time string.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/vtt2ass/ass_line.rb', line 67 def to_subs_time(str) n = [] x = str.split(/[:.]/).map(&:to_i) ms_len = 2 h_len = 1 x[3] = "0.#{x[3].to_s.rjust(3, '0')}" sx = (x[0] * 60 * 60) + (x[1] * 60) + x[2] + x[3].to_f sx = format('%.2f', sx).split('.') n.unshift(pad_time_num('.', sx[1], ms_len)) sx = sx[0].to_f n.unshift(pad_time_num(':', (sx % 60).to_i, 2)) n.unshift(pad_time_num(':', (sx / 60).floor % 60, 2)) n.unshift(pad_time_num('', (sx / 3600).floor % 60, h_len)) n.join end |