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
ago(time = ::Time.now)
click to toggle source
# File lib/richunits/weekdays.rb, line 18 def ago(time = ::Time.now) step :down, time end
since(time = ::Time.now)
click to toggle source
# File lib/richunits/weekdays.rb, line 24 def since(time = ::Time.now) step :up, time end
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