Class: Schedule
Defined Under Namespace
Constant Summary collapse
- WEEKDAYS =
Sunday through Saturday
'UMTWRFS'
Instance Method Summary collapse
- #downtime_minutes_from(localtime) ⇒ Object
-
#initialize(str) ⇒ Schedule
constructor
A new instance of Schedule.
- #permits?(localtime) ⇒ Boolean
Constructor Details
#initialize(str) ⇒ Schedule
Returns a new instance of Schedule.
5 6 7 8 9 10 |
# File 'lib/abstractivator/schedule/schedule.rb', line 5 def initialize(str) @periods = parse_periods(str) unless @periods.any? raise 'At least one period must be specified' end end |
Instance Method Details
#downtime_minutes_from(localtime) ⇒ Object
16 17 18 19 20 |
# File 'lib/abstractivator/schedule/schedule.rb', line 16 def downtime_minutes_from(localtime) return 0 if permits?(localtime) wmin = Wmin.from_localtime(localtime) @periods.map{|p| (p.start - wmin + Wmin::WEEK) % Wmin::WEEK}.min end |
#permits?(localtime) ⇒ Boolean
12 13 14 |
# File 'lib/abstractivator/schedule/schedule.rb', line 12 def permits?(localtime) @periods.any?{|p| p.includes?(localtime)} end |