Sha256: 320ada633f02d25ecc45b27858bc39fab3010f4a00c13534955e492caa31ee72
Contents?: true
Size: 1.1 KB
Versions: 1
Compression:
Stored size: 1.1 KB
Contents
module EncoderTools module Subtitles class Subtitle attr_accessor :range, :text def initialize(range, text) @range, @text = range, text end def offset range.begin end def offset=(offset) self.range = offset..(offset + duration) end def duration range.end - range.begin end def duration=(duration) self.range = offset..(offset + duration) end def ==(other) other.is_a?(self.class) && other.range == self.range && other.text == self.text end def range_string "#{timestamp range.begin} --> #{timestamp range.end}" end def to_s [range_string, text].join("\n") end def timestamp(value) self.class.timestamp(value) end 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 end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
encoder-tools-1.0.0 | lib/encoder-tools/subtitles/subtitle.rb |