Class: EncoderTools::Subtitles::Subtitle
- Inherits:
-
Object
- Object
- EncoderTools::Subtitles::Subtitle
- Defined in:
- lib/encoder-tools/subtitles/subtitle.rb
Instance Attribute Summary collapse
-
#range ⇒ Object
Returns the value of attribute range.
-
#text ⇒ Object
Returns the value of attribute text.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #duration ⇒ Object
- #duration=(duration) ⇒ Object
-
#initialize(range, text) ⇒ Subtitle
constructor
A new instance of Subtitle.
- #offset ⇒ Object
- #offset=(offset) ⇒ Object
- #range_string ⇒ Object
- #timestamp(value) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(range, text) ⇒ Subtitle
Returns a new instance of Subtitle.
6 7 8 |
# File 'lib/encoder-tools/subtitles/subtitle.rb', line 6 def initialize(range, text) @range, @text = range, text end |
Instance Attribute Details
#range ⇒ Object
Returns the value of attribute range.
4 5 6 |
# File 'lib/encoder-tools/subtitles/subtitle.rb', line 4 def range @range end |
#text ⇒ Object
Returns the value of attribute text.
4 5 6 |
# File 'lib/encoder-tools/subtitles/subtitle.rb', line 4 def text @text end |
Class Method Details
.timestamp(value) ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/encoder-tools/subtitles/subtitle.rb', line 44 def self.(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 |
Instance Method Details
#==(other) ⇒ Object
26 27 28 29 30 |
# 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 ⇒ Object
18 19 20 |
# File 'lib/encoder-tools/subtitles/subtitle.rb', line 18 def duration range.end - range.begin end |
#duration=(duration) ⇒ Object
22 23 24 |
# File 'lib/encoder-tools/subtitles/subtitle.rb', line 22 def duration=(duration) self.range = offset..(offset + duration) end |
#offset ⇒ Object
10 11 12 |
# File 'lib/encoder-tools/subtitles/subtitle.rb', line 10 def offset range.begin end |
#offset=(offset) ⇒ Object
14 15 16 |
# File 'lib/encoder-tools/subtitles/subtitle.rb', line 14 def offset=(offset) self.range = offset..(offset + duration) end |
#range_string ⇒ Object
32 33 34 |
# File 'lib/encoder-tools/subtitles/subtitle.rb', line 32 def range_string "#{timestamp range.begin} --> #{timestamp range.end}" end |
#timestamp(value) ⇒ Object
40 41 42 |
# File 'lib/encoder-tools/subtitles/subtitle.rb', line 40 def (value) self.class.(value) end |
#to_s ⇒ Object
36 37 38 |
# File 'lib/encoder-tools/subtitles/subtitle.rb', line 36 def to_s [range_string, text].join("\n") end |