Sha256: ec25a637a85c3f71048ba4c869e1701d0d14118be30cdefa490023270648790e
Contents?: true
Size: 858 Bytes
Versions: 1
Compression:
Stored size: 858 Bytes
Contents
module Substitute class Line def initialize(text) self.text = text 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(':')}.#{thous}" 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 end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
substitute-0.1.0 | lib/substitute/line.rb |