Sha256: 7f3f4cf099933a667daa3f512526b9b4cd3aef5205b7760e9a7b0f4a9f371bcd
Contents?: true
Size: 1006 Bytes
Versions: 1
Compression:
Stored size: 1006 Bytes
Contents
module Substitute class Line def initialize(text, options = {}) self.text = text @srt = options[:srt] end attr_accessor :text def to_s if line_with_identifier? "\n#{identifier}\n#{start} --> #{finish}\n#{remaining_text}" else text end end def parts @_parts ||= text.split(" ") end def identifier parts[0] end def start convert_timestamp(parts[1]) end def finish convert_timestamp(parts[2]) end def convert_timestamp(timestamp) times = timestamp.split(":") frames = times[3].to_i thous = (frames * 40).to_s.rjust(3, "0") "#{times[0..2].join(":")}#{sep}#{thous}" end def sep return "," if srt? "." end def remaining_text parts[3..-1].join(" ") end def line_with_identifier? return unless parts[0] parts[0].to_i.to_s == parts[0] end private def srt? @srt end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
substitute-0.2.0 | lib/substitute/line.rb |