class Substitute::Line

Attributes

text[RW]

Public Class Methods

new(text, options = {}) click to toggle source
# File lib/substitute/line.rb, line 3
def initialize(text, options = {})
  self.text = text
  @srt = options[:srt]
end

Public Instance Methods

convert_timestamp(timestamp) click to toggle source
# File lib/substitute/line.rb, line 34
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
finish() click to toggle source
# File lib/substitute/line.rb, line 30
def finish
  convert_timestamp(parts[2])
end
identifier() click to toggle source
# File lib/substitute/line.rb, line 22
def identifier
  parts[0]
end
line_with_identifier?() click to toggle source
# File lib/substitute/line.rb, line 50
def line_with_identifier?
  return unless parts[0]
  parts[0].to_i.to_s == parts[0]
end
parts() click to toggle source
# File lib/substitute/line.rb, line 18
def parts
  @_parts ||= text.split(" ")
end
remaining_text() click to toggle source
# File lib/substitute/line.rb, line 46
def remaining_text
  parts[3..-1].join(" ")
end
sep() click to toggle source
# File lib/substitute/line.rb, line 41
def sep
  return "," if srt?
  "."
end
start() click to toggle source
# File lib/substitute/line.rb, line 26
def start
  convert_timestamp(parts[1])
end
to_s() click to toggle source
# File lib/substitute/line.rb, line 10
def to_s
  if line_with_identifier?
    "\n#{identifier}\n#{start} --> #{finish}\n#{remaining_text}"
  else
    text
  end
end

Private Instance Methods

srt?() click to toggle source
# File lib/substitute/line.rb, line 57
def srt?
  @srt
end