module TimeMath::Measure

@private

Constants

PLURALS

Public Class Methods

measure(from, to, options = {}) click to toggle source
# File lib/time_math/measure.rb, line 14
def self.measure(from, to, options = {})
  select_units(options).reverse.inject({}) do |res, unit|
    span, from = Units.get(unit).measure_rem(from, to)
    res.merge(PLURALS[unit] => span)
  end
end
select_units(options) click to toggle source
# File lib/time_math/measure.rb, line 21
def self.select_units(options)
  units = Units.names
  units.delete(:week) if options[:weeks] == false

  if (idx = units.index(options[:upto]))
    units = units.first(idx + 1)
  end

  units
end