class RichUnits::Weekdays

Weekdays

The Weekdays class provides useful weekday terminology.

Thanks to Dave Hoover and Ryan Platte for the Weekdays implementation.

Constants

ONE_DAY
WEEKDAYS

Public Class Methods

new(n) click to toggle source
# File lib/richunits/weekdays.rb, line 14
def initialize(n)
  @n = n
end

Public Instance Methods

after(time = ::Time.now)
Alias for: since
ago(time = ::Time.now) click to toggle source
# File lib/richunits/weekdays.rb, line 18
def ago(time = ::Time.now)
  step :down, time
end
Also aliased as: until, before
before(time = ::Time.now)
Alias for: ago
from_now(time = ::Time.now)
Alias for: since
since(time = ::Time.now) click to toggle source
# File lib/richunits/weekdays.rb, line 24
def since(time = ::Time.now)
  step :up, time
end
Also aliased as: from_now, after
until(time = ::Time.now)
Alias for: ago

Private Instance Methods

step(direction, original_time) click to toggle source
# File lib/richunits/weekdays.rb, line 32
def step(direction, original_time)
  result = original_time
  time = ONE_DAY

  compare = direction == :up ? ">" : "<"
  time *= -1 if direction == :down

  @n.times do
    result += time until result.send(compare, original_time) && WEEKDAYS.member?(result.wday)
    original_time = result
  end
  result
end