Module: NthDay

Defined in:
lib/nth_day.rb,
lib/nth_day/version.rb

Constant Summary collapse

VERSION =
"0.0.1"

Class Method Summary collapse

Class Method Details

.next_occurrence(day, now = Date.today) ⇒ Object



5
6
7
8
9
# File 'lib/nth_day.rb', line 5

def self.next_occurrence(day, now=Date.today)
  n = day.split.first[/\d/].to_i
  w = self.wday_named(day.split.last)
  now.step(now + 37).select{|d| d.nth_wday?(n, w) }.first
end

.wday_named(name) ⇒ Object



11
12
13
# File 'lib/nth_day.rb', line 11

def self.wday_named(name)
  ["su", "mo", "tu", "we", "th", "fr", "sa"].index(name[0..1].downcase)
end