Module: Schedule::Wmin

Defined in:
lib/abstractivator/schedule/schedule.rb

Overview

a ‘wmin’ is a week-minute: a time in any given week, represented as the number of minutes since midnight on Sunday. Saturday 23:59 is the largest wmin (7 * 24 * 60 - 1)

Constant Summary collapse

DAY =
24 * 60
WEEK =
7 * DAY

Class Method Summary collapse

Class Method Details

.add_day(wmin) ⇒ Object



99
100
101
# File 'lib/abstractivator/schedule/schedule.rb', line 99

def self.add_day(wmin)
  wmin + DAY
end

.from_localtime(localtime) ⇒ Object



95
96
97
# File 'lib/abstractivator/schedule/schedule.rb', line 95

def self.from_localtime(localtime)
  make(localtime.wday, localtime.hour, localtime.min)
end

.make(day, hour, minute) ⇒ Object



91
92
93
# File 'lib/abstractivator/schedule/schedule.rb', line 91

def self.make(day, hour, minute)
  minute + hour * 60 + day * 24 * 60
end

.parse(day_char, hour, min) ⇒ Object



83
84
85
86
87
88
89
# File 'lib/abstractivator/schedule/schedule.rb', line 83

def self.parse(day_char, hour, min)
  day = WEEKDAYS.index(day_char)
  unless day
    raise "Invalid day specifier: '#{day_char}'"
  end
  make(day, hour.to_i, min.to_i)
end