Class: Subtitle

Inherits:
Object
  • Object
show all
Defined in:
lib/rsrt/subtitle.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(details = {}) ⇒ Subtitle

Returns a new instance of Subtitle.



5
6
7
8
9
# File 'lib/rsrt/subtitle.rb', line 5

def initialize(details={})
  @id = details[:id].to_i
  @text = details[:text]
  parse_time_range(details[:time_range])
end

Instance Attribute Details

#end_timeObject (readonly)

Returns the value of attribute end_time.



3
4
5
# File 'lib/rsrt/subtitle.rb', line 3

def end_time
  @end_time
end

#idObject (readonly)

Returns the value of attribute id.



3
4
5
# File 'lib/rsrt/subtitle.rb', line 3

def id
  @id
end

#start_timeObject (readonly)

Returns the value of attribute start_time.



3
4
5
# File 'lib/rsrt/subtitle.rb', line 3

def start_time
  @start_time
end

#textObject (readonly)

Returns the value of attribute text.



3
4
5
# File 'lib/rsrt/subtitle.rb', line 3

def text
  @text
end

Instance Method Details

#shift_time_range_backward(shift) ⇒ Object



16
17
18
19
# File 'lib/rsrt/subtitle.rb', line 16

def shift_time_range_backward(shift)
  @start_time.from_ms(@start_time.to_ms - shift)
  @end_time.from_ms(@end_time.to_ms - shift)
end

#shift_time_range_forward(shift) ⇒ Object



11
12
13
14
# File 'lib/rsrt/subtitle.rb', line 11

def shift_time_range_forward(shift)
  @start_time.from_ms(@start_time.to_ms + shift)
  @end_time.from_ms(@end_time.to_ms + shift)
end

#to_sObject



21
22
23
# File 'lib/rsrt/subtitle.rb', line 21

def to_s
  @id.to_s + "\n" + @start_time.to_s + " --> " + @end_time.to_s + "\n" + @text.to_s
end