class Captions::Cue

Constants

ALIGNMENT

Text Properties supported

COLOR
POSITION
TEXT_PROPERTIES

List of Text Properties

Attributes

duration[RW]
end_time[RW]
number[RW]
properties[RW]
start_time[RW]
text[RW]

Public Class Methods

new(cue_number = nil) click to toggle source

Creates a new Cue class Each cue denotes a subtitle.

# File lib/captions/cue.rb, line 17
def initialize(cue_number = nil)
  self.text = nil
  self.start_time = nil
  self.end_time = nil
  self.duration = nil
  self.number = cue_number
  self.properties = {}
end

Public Instance Methods

<=>(other_cue) click to toggle source
# File lib/captions/cue.rb, line 89
def <=>(other_cue)
  self.start_time <=> other_cue.start_time
end
add_text(text) click to toggle source

Adds text. If text is already found, new-line is appended.

# File lib/captions/cue.rb, line 81
def add_text(text)
  if self.text.nil?
    self.text = text
  else
    self.text += "\n" + text
  end
end
change_frame_rate(old_rate, new_rate) click to toggle source

Changes start-time, end-time and duration based on new frame-rate

# File lib/captions/cue.rb, line 74
def change_frame_rate(old_rate, new_rate)
  self.start_time = convert_frame_rate(self.start_time, old_rate, new_rate)
  self.end_time = convert_frame_rate(self.end_time, old_rate, new_rate)
  self.duration = convert_frame_rate(self.duration, old_rate, new_rate)
end
serialize(fps) click to toggle source

Serializes the values set for the cue. Converts start-time, end-time and duration to milliseconds If duration is not found, it will be calculated based on start-time and end-time.

# File lib/captions/cue.rb, line 55
def serialize(fps)
  raise InvalidSubtitle, "Subtitle should have start time" if self.start_time.nil?
  raise InvalidSubtitle, "Subtitle shold have end time" if self.end_time.nil?

  begin
    ms_per_frame = (1000.0 / fps)
    self.start_time = convert_to_msec(self.start_time, ms_per_frame)
    self.end_time = convert_to_msec(self.end_time, ms_per_frame)
    if duration.nil?
      self.duration = self.end_time - self.start_time
    else
      self.duration = convert_to_msec(self.duration, ms_per_frame)
    end
  rescue
    raise InvalidSubtitle, "Cannot calculate start-time or end-time"
  end
end
set_time(start_time, end_time, duration = nil) click to toggle source

Sets the time for the cue. Both start-time and end-time can be passed together. This just assigns the value passed.

# File lib/captions/cue.rb, line 29
def set_time(start_time, end_time, duration = nil)
  self.start_time = start_time
  self.end_time = end_time
  self.duration = duration
end