Class: EncoderTools::Subtitles::Subtitle

Inherits:
Object
  • Object
show all
Defined in:
lib/encoder-tools/subtitles/subtitle.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#rangeObject

Returns the value of attribute range.



4
5
6
# File 'lib/encoder-tools/subtitles/subtitle.rb', line 4

def range
  @range
end

#textObject

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.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

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

#durationObject



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

#offsetObject



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_stringObject



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 timestamp(value)
  self.class.timestamp(value)
end

#to_sObject



36
37
38
# File 'lib/encoder-tools/subtitles/subtitle.rb', line 36

def to_s
  [range_string, text].join("\n")
end