class SRT::Line

Attributes

display_coordinates[RW]
end_time[RW]
error[RW]
sequence[RW]
start_time[RW]
text[W]

Public Class Methods

new(options={}) click to toggle source
# File lib/srt/line.rb, line 14
def initialize(options={})
  options.each do |k,v|
    self.send("#{k}=",v)
  end
end

Public Instance Methods

clone() click to toggle source
# File lib/srt/line.rb, line 20
def clone
  clone = Line.new
  clone.display_coordinates = display_coordinates
  clone.sequence = sequence
  clone.start_time = start_time
  clone.end_time = end_time
  clone.error = error
  clone.text = text.clone
  clone
end
empty?() click to toggle source
# File lib/srt/line.rb, line 31
def empty?
  sequence.nil? && start_time.nil? && end_time.nil? && text.empty?
end
text() click to toggle source
# File lib/srt/line.rb, line 10
def text
  @text ||= []
end
time_str(subframe_separator=",") click to toggle source
# File lib/srt/line.rb, line 35
def time_str(subframe_separator=",")
  [@start_time, @end_time].map { |t|  f=sprintf("%.3f", t); ip=f[0,f.size-4].to_i;fp=f[-3,3]; "%02d:%02d:%02d#{subframe_separator}%s" % [ip / 3600, (ip % 3600) / 60, ip % 60,fp] }.join(" --> ")
end
to_s(time_str_function=:time_str) click to toggle source
# File lib/srt/line.rb, line 43
def to_s(time_str_function=:time_str)
  content = text.empty? ? [''] : text
  coordinates = display_coordinates ? display_coordinates : ""
  [sequence, send(time_str_function) + coordinates, content, ""].flatten.join("\n")
end
webvtt_time_str() click to toggle source
# File lib/srt/line.rb, line 39
def webvtt_time_str
  time_str(".")
end