Class: MovingWords::CaptionBlock
- Inherits:
-
Object
- Object
- MovingWords::CaptionBlock
- Defined in:
- lib/moving_words/caption_block.rb
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
-
#end_time ⇒ Object
Returns the value of attribute end_time.
-
#start_time ⇒ Object
Returns the value of attribute start_time.
Class Method Summary collapse
-
.human_offset(offset_in_milliseconds, options = {}) ⇒ Object
Public: Converts a millisecond offset to a more human-readable format of hh:mm:ss.
Instance Method Summary collapse
-
#initialize(start_time, end_time, content) ⇒ CaptionBlock
constructor
Public: Sets up a new CaptionBlock with the given start_time, end_time, and content.
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
#content ⇒ Object
Returns the value of attribute content.
3 4 5 |
# File 'lib/moving_words/caption_block.rb', line 3 def content @content end |
#end_time ⇒ Object
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_time ⇒ Object
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, = {}) 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 [:milliseconds] time << ".%03d" % milliseconds end time end |