Module: TimeBoots::Measure

Defined in:
lib/time_boots/measure.rb

Constant Summary collapse

PLURALS =
{
  year: :years,
  month: :months,
  week: :weeks,
  day: :days,
  hour: :hours,
  min: :minutes,
  sec: :seconds
}.freeze

Class Method Summary collapse

Class Method Details

.measure(from, to, options = {}) ⇒ Object



14
15
16
17
18
19
# File 'lib/time_boots/measure.rb', line 14

def self.measure(from, to, options = {})
  select_steps(options).reverse.inject({}) do |res, step|
    span, from = Boot.get(step).measure_rem(from, to)
    res.merge(PLURALS[step] => span)
  end
end

.select_steps(options) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/time_boots/measure.rb', line 21

def self.select_steps(options)
  steps = Boot.steps
  steps.delete(:week) if options[:weeks] == false

  if (idx = steps.index(options[:max_step]))
    steps = steps.first(idx + 1)
  end

  steps
end