class EncoderTools::Subtitles::Subtitle

Attributes

range[RW]
text[RW]

Public Class Methods

new(range, text) click to toggle source
# File lib/encoder-tools/subtitles/subtitle.rb, line 6
def initialize(range, text)
  @range, @text = range, text
end
timestamp(value) click to toggle source
# File lib/encoder-tools/subtitles/subtitle.rb, line 44
def self.timestamp(value)
  seconds = value.to_i
  millis = ((value - seconds) * 1000).to_i
  minutes, seconds = seconds.divmod(60)
  hours, minutes = minutes.divmod(60)

  "%02d:%02d:%02d,%03d" % [hours, minutes, seconds, millis]
end

Public Instance Methods

==(other) click to toggle source
# File lib/encoder-tools/subtitles/subtitle.rb, line 26
def ==(other)
  other.is_a?(self.class) &&
    other.range == self.range &&
    other.text == self.text
end
duration() click to toggle source
# File lib/encoder-tools/subtitles/subtitle.rb, line 18
def duration
  range.end - range.begin
end
duration=(duration) click to toggle source
# File lib/encoder-tools/subtitles/subtitle.rb, line 22
def duration=(duration)
  self.range = offset..(offset + duration)
end
offset() click to toggle source
# File lib/encoder-tools/subtitles/subtitle.rb, line 10
def offset
  range.begin
end
offset=(offset) click to toggle source
# File lib/encoder-tools/subtitles/subtitle.rb, line 14
def offset=(offset)
  self.range = offset..(offset + duration)
end
range_string() click to toggle source
# File lib/encoder-tools/subtitles/subtitle.rb, line 32
def range_string
  "#{timestamp range.begin} --> #{timestamp range.end}"
end
timestamp(value) click to toggle source
# File lib/encoder-tools/subtitles/subtitle.rb, line 40
def timestamp(value)
  self.class.timestamp(value)
end
to_s() click to toggle source
# File lib/encoder-tools/subtitles/subtitle.rb, line 36
def to_s
  [range_string, text].join("\n")
end