Class: MovingWords::CaptionBlock

Inherits:
Object
  • Object
show all
Defined in:
lib/moving_words/caption_block.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(start_time, end_time, content) ⇒ CaptionBlock

Public: Sets up a new CaptionBlock with the given start_time, end_time, and content.

start_time - Offset in milliseconds from the

beginning of the video to this `CaptionBlock`

end_time - Offset in milliseconds from the

beginning of the video to the end of this
`CaptionBlock`

content - The contents of this ‘CaptionBlock`



14
15
16
17
18
# File 'lib/moving_words/caption_block.rb', line 14

def initialize(start_time, end_time, content)
  self.start_time  = start_time
  self.end_time = end_time
  self.content = content
end

Instance Attribute Details

#contentObject

Returns the value of attribute content.



3
4
5
# File 'lib/moving_words/caption_block.rb', line 3

def content
  @content
end

#end_timeObject

Returns the value of attribute end_time.



3
4
5
# File 'lib/moving_words/caption_block.rb', line 3

def end_time
  @end_time
end

#start_timeObject

Returns the value of attribute start_time.



3
4
5
# File 'lib/moving_words/caption_block.rb', line 3

def start_time
  @start_time
end

Class Method Details

.human_offset(offset_in_milliseconds, options = {}) ⇒ Object

Public: Converts a millisecond offset to a more human-readable format of hh:mm:ss.

offset_in_milliseconds - The millisecond offset to convert. options - Formatting options

milliseconds: Includes milliseconds in the
    display output.

Examples:

CaptionBlock.human_offset(132212)
=> "2:12"

CaptionBlock.human_offset(132212, milliseconds: true)
=> "2:12.212"

CaptionBlock.human_offset(11075307)
=> "3:04:35"


38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/moving_words/caption_block.rb', line 38

def self.human_offset(offset_in_milliseconds, options = {})
  hours = offset_in_milliseconds / 3600000
  minutes = (offset_in_milliseconds % 3600000) / 60000
  seconds = (offset_in_milliseconds % 60000) / 1000
  milliseconds = offset_in_milliseconds % 1000

  time = ""
  if hours > 0
    time << "#{hours}:"
    time << "%02d:" % minutes
  else
    time << "%1d:" % minutes
  end

  time << "%02d" % seconds

  if options[:milliseconds]
    time << ".%03d" % milliseconds
  end

  time
end