module TimeCalc::Units

@private Unit-related constants and utilities for fetching their values

Constants

ALL
DEFAULTS
MULTIPLIERS
NATURAL
STRUCTURAL
SYNONYMS

Public Class Methods

call(unit) click to toggle source
# File lib/time_calc/units.rb, line 39
def self.call(unit)
  SYNONYMS.fetch(unit, unit)
          .tap { |u| ALL.include?(u) or fail ArgumentError, "Unsupported unit: #{u}" }
end
multiplier_for(klass, unit, precise: false) click to toggle source
# File lib/time_calc/units.rb, line 44
def self.multiplier_for(klass, unit, precise: false)
  res = MULTIPLIERS.fetch(unit)
  d = MULTIPLIERS.fetch(:day)
  case klass.name
  when 'Time'
    res
  when 'DateTime'
    res / d.to_f
  when 'Date'
    precise ? res / d.to_f : res / d
  end
end