Class: Subber::Subtitle

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Subtitle

Returns a new instance of Subtitle.



7
8
9
10
11
12
# File 'lib/subber/subtitle.rb', line 7

def initialize(attributes)
  @counter = attributes[:counter]
  @start_time = attributes[:start_time]
  @end_time = attributes[:end_time]
  @content = attributes[:content]
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



5
6
7
# File 'lib/subber/subtitle.rb', line 5

def content
  @content
end

#counterObject (readonly)

Returns the value of attribute counter.



2
3
4
# File 'lib/subber/subtitle.rb', line 2

def counter
  @counter
end

#end_timeObject (readonly)

Returns the value of attribute end_time.



4
5
6
# File 'lib/subber/subtitle.rb', line 4

def end_time
  @end_time
end

#start_timeObject (readonly)

Returns the value of attribute start_time.



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

def start_time
  @start_time
end

Instance Method Details

#as_jsonObject



14
15
16
17
18
19
20
21
# File 'lib/subber/subtitle.rb', line 14

def as_json
  {
    'counter' => counter,
    'start_time' => start_time,
    'end_time' => end_time,
    'content' => content
  }
end

#shift(ms) ⇒ Subber::Subtitle

Return a copy with shifted subtitle

Parameters:

  • miliseconds (Integer)

    Can be both positive and negative

Returns:



26
27
28
29
30
31
32
33
# File 'lib/subber/subtitle.rb', line 26

def shift(ms)
  self.class.new(
    counter: counter,
    start_time: start_time + ms,
    end_time: end_time + ms,
    content: content
  )
end

#shift!(ms) ⇒ Object

mutates the current subtitle’s start and end time by ms

Parameters:

  • miliseconds (Integer)

    Can be both positive and negative



38
39
40
41
# File 'lib/subber/subtitle.rb', line 38

def shift!(ms)
  @start_time += ms
  @end_time += ms
end