class Integer

Monkey-patched {Integer} class enabled to return {Timerizer::Duration}s. @example

5.minutes
# => 5 minutes

@see Timerizer::Duration::UNITS

Private Class Methods

_define_duration_unit(unit) click to toggle source

@!macro [attach] _define_duration_unit

@method $1(other = nil)

Return a {Timerizer::Duration} with `self` of the given unit. This
method is a helper that is equivalent to
`Timerizer::Duration::new($1: self)`.

@param [Timerizer::Duration, nil] other Another duration to add to the
  resulting duration, if present. This argument allows "chaining" multiple
  durations together, to combine multiple units succiently.

@return [Timerizer::Duration] the quantity of the unit in the duration.

@see Timerizer::Duration#initialize

@example
  n.$1 == Timerizer::Duration.new($1: n)
  5.minutes == Timerizer::Duration.new(minutes: 5)
  (1.week 1.day) == 8.days # "Chaining" multiple units
  (n.$1 x.minutes) == (n.$1 + x.minutes)
# File lib/timerizer.rb, line 203
def self._define_duration_unit(unit)
  define_method(unit) do |other = nil|
    duration = Timerizer::Duration.new(unit => self)

    if other.nil?
      duration
    else
      duration + other
    end
  end
end