class SmD::SmD
Constants
- DEFAULT_RANGE
- MS_PER_HOUR
- MS_PER_MINUTE
- MS_PER_SECOND
Public Class Methods
new(params = {})
click to toggle source
# File lib/smd.rb, line 12 def initialize params = {} @range = params[:range] || DEFAULT_RANGE @ms_per_unit = params[:ms_per_unit] || MS_PER_HOUR end
Public Instance Methods
at(units)
click to toggle source
# File lib/smd.rb, line 29 def at units (units * ms_per_unit) + ((current_ms / range_in_ms).floor * range_in_ms) end
date(units)
click to toggle source
# File lib/smd.rb, line 41 def date units Time.at(at(units) / MS_PER_SECOND) # Convert from milliseconds to seconds end
from(milliseconds)
click to toggle source
# File lib/smd.rb, line 45 def from milliseconds ((milliseconds % range_in_ms) / ms_per_unit).floor end
max()
click to toggle source
# File lib/smd.rb, line 37 def max date (range - 1) end
min()
click to toggle source
# File lib/smd.rb, line 33 def min date (-1 * (range / 2)) end
ms_per_unit()
click to toggle source
# File lib/smd.rb, line 25 def ms_per_unit @ms_per_unit end
now()
click to toggle source
# File lib/smd.rb, line 49 def now from current_ms end
range()
click to toggle source
# File lib/smd.rb, line 17 def range @range end
range_in_ms()
click to toggle source
# File lib/smd.rb, line 21 def range_in_ms range * ms_per_unit end
Private Instance Methods
current_ms()
click to toggle source
# File lib/smd.rb, line 55 def current_ms Time.now.gmtime.to_f * MS_PER_SECOND # Convert from seconds to milliseconds end