class Qwik::SmilTime

Public Class Methods

at_smil(arg) click to toggle source
# File vendor/qwik/lib/qwik/smil-time.rb, line 16
def self.at_smil(arg)
  raise 'arg must be String' unless arg.is_a?(String)
  hour, min, sec, frame = SmilTime.parse_smil(arg)
  return SmilTime.gm(1970, 1, 1, hour, min, sec, frame_to_usec(frame))
end
frame_to_usec(frame) click to toggle source
# File vendor/qwik/lib/qwik/smil-time.rb, line 22
def self.frame_to_usec(frame)
  return (1000000.0 * frame.to_f / 30.0).to_i
end
parse_smil(str) click to toggle source
# File vendor/qwik/lib/qwik/smil-time.rb, line 30
def self.parse_smil(str)
  hour = min = sec = frame = 0
  if str.include?('.')
    str, frame = str.split('.', 2)
    frame = with_range(frame.to_i, 0, 29)
  end
  ar = str.split(/:/)
  sec = with_range(ar.pop.to_i, 0, 59)
  min = with_range(ar.pop.to_i, 0, 59)
  hour = with_range(ar.pop.to_i, 0, 999999) # without max
  return [hour, min, sec, frame]
end
usec_to_frame(usec) click to toggle source
# File vendor/qwik/lib/qwik/smil-time.rb, line 26
def self.usec_to_frame(usec)
  return (30.0 * usec.to_f / 1000000.0 + 0.5).to_i  # half adjust
end
with_range(n, min, max) click to toggle source
# File vendor/qwik/lib/qwik/smil-time.rb, line 43
def self.with_range(n, min, max)
  n = min if n < min
  n = max if max < n
  return n
end

Public Instance Methods

to_smil() click to toggle source
# File vendor/qwik/lib/qwik/smil-time.rb, line 9
def to_smil
  str = self.strftime('%H:%M:%S')
  frame = SmilTime.usec_to_frame(self.usec)
  str += '.'+sprintf('%02d', frame) if 0 < frame
  return str
end