Class: SRT::Parser
- Inherits:
-
Object
- Object
- SRT::Parser
- Defined in:
- lib/srt/parser.rb
Class Method Summary collapse
- .framerate(framerate_string) ⇒ Object
- .id(id_string) ⇒ Object
- .timecode(timecode_string) ⇒ Object
- .timespan(timespan_string) ⇒ Object
Class Method Details
.framerate(framerate_string) ⇒ Object
4 5 6 7 |
# File 'lib/srt/parser.rb', line 4 def framerate(framerate_string) mres = framerate_string.match(/(?<fps>\d+((\.)?\d+))(fps)/) mres ? mres["fps"].to_f : nil end |
.id(id_string) ⇒ Object
9 10 11 12 |
# File 'lib/srt/parser.rb', line 9 def id(id_string) mres = id_string.match(/#(?<id>\d+)/) mres ? mres["id"].to_i : nil end |
.timecode(timecode_string) ⇒ Object
14 15 16 17 |
# File 'lib/srt/parser.rb', line 14 def timecode(timecode_string) mres = timecode_string.match(/(?<h>\d+):(?<m>\d+):(?<s>\d+),(?<ms>\d+)/) mres ? "#{mres["h"].to_i * 3600 + mres["m"].to_i * 60 + mres["s"].to_i}.#{mres["ms"]}".to_f : nil end |
.timespan(timespan_string) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/srt/parser.rb', line 19 def timespan(timespan_string) factors = { "ms" => 0.001, "s" => 1, "m" => 60, "h" => 3600 } mres = timespan_string.match(/(?<amount>(\+|-)?\d+((\.)?\d+)?)(?<unit>ms|s|m|h)/) mres ? mres["amount"].to_f * factors[mres["unit"]] : nil end |