Class: Schedule

Inherits:
Object show all
Defined in:
lib/abstractivator/schedule/schedule.rb

Defined Under Namespace

Modules: Wmin Classes: Period

Constant Summary collapse

WEEKDAYS =

Sunday through Saturday

'UMTWRFS'

Instance Method Summary collapse

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

Returns:

  • (Boolean)


12
13
14
# File 'lib/abstractivator/schedule/schedule.rb', line 12

def permits?(localtime)
  @periods.any?{|p| p.includes?(localtime)}
end