Class: Voot::Timestamp

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/voot/timestamp.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(seconds_since_origin) ⇒ Timestamp

Returns a new instance of Timestamp.



7
8
9
# File 'lib/voot/timestamp.rb', line 7

def initialize(seconds_since_origin)
  @seconds_since_origin = seconds_since_origin.to_f.round(3)
end

Instance Attribute Details

#seconds_since_originObject (readonly)

Returns the value of attribute seconds_since_origin.



5
6
7
# File 'lib/voot/timestamp.rb', line 5

def seconds_since_origin
  @seconds_since_origin
end

Instance Method Details

#<=>(other) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/voot/timestamp.rb', line 11

def <=>(other)
  if other.is_a?(Numeric)
    seconds_since_origin <=> other
  else
    seconds_since_origin <=> other.seconds_since_origin
  end
end

#hoursObject



19
20
21
# File 'lib/voot/timestamp.rb', line 19

def hours
  seconds_since_origin.to_i / 3600
end

#millisecondsObject



31
32
33
# File 'lib/voot/timestamp.rb', line 31

def milliseconds
  milliseconds_since_origin.round % 1000
end

#minutesObject



23
24
25
# File 'lib/voot/timestamp.rb', line 23

def minutes
  seconds_without_hours.to_i / 60
end

#secondsObject



27
28
29
# File 'lib/voot/timestamp.rb', line 27

def seconds
  seconds_since_origin.to_i % 60
end

#to_webvttObject



35
36
37
# File 'lib/voot/timestamp.rb', line 35

def to_webvtt
  "%02d:%02d:%02d.%03d" % [hours, minutes, seconds, milliseconds]
end