class Subs::SubRipTime

Constants

ZERO

Public Class Methods

new(hour, minute, second, millisecond) click to toggle source
# File lib/subs/sub_rip_time.rb, line 4
def initialize(hour, minute, second, millisecond)
  @ms = millisecond
  @ms += second * 1000
  @ms += minute * 60 * 1000
  @ms += hour * 60 * 60 * 1000
end

Public Instance Methods

+(amount) click to toggle source
# File lib/subs/sub_rip_time.rb, line 22
def +(amount)
  value = amount.is_a?(SubRipTime) ? amount.total_ms : Integer(amount)
  self.class.new(0, 0, 0, [@ms + value, 0].max)
end
-(amount) click to toggle source
# File lib/subs/sub_rip_time.rb, line 17
def -(amount)
  value = amount.is_a?(SubRipTime) ? amount.total_ms : Integer(amount)
  self.class.new(0, 0, 0, [@ms - value, 0].max)
end
hours() click to toggle source
# File lib/subs/sub_rip_time.rb, line 27
def hours
  @ms / (1000 * 60 * 60)
end
milliseconds() click to toggle source
# File lib/subs/sub_rip_time.rb, line 39
def milliseconds
  @ms % 1000
end
minutes() click to toggle source
# File lib/subs/sub_rip_time.rb, line 31
def minutes
  (@ms / (1000 * 60)) % 60
end
seconds() click to toggle source
# File lib/subs/sub_rip_time.rb, line 35
def seconds
  (@ms / 1000) % 60
end
to_s() click to toggle source
# File lib/subs/sub_rip_time.rb, line 43
def to_s
  "%02d:%02d:%02d,%03d" % [hours, minutes, seconds, milliseconds]
end
total_ms() click to toggle source
# File lib/subs/sub_rip_time.rb, line 13
def total_ms
  @ms
end