Class: IceT::Schedule

Inherits:
Object
  • Object
show all
Extended by:
Forwardable, Conversions::Schedule
Defined in:
lib/ice_t/schedule.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Conversions::Schedule

from_json, from_yaml

Constructor Details

#initialize(opts = {}) ⇒ Schedule

Returns a new instance of Schedule.



16
17
18
19
20
21
22
23
24
25
# File 'lib/ice_t/schedule.rb', line 16

def initialize(opts={})
  opts = {
    start_time: nil,
    end_time: nil
  }.merge(opts)
  @start_time = opts[:start_time]
  @end_time   = opts[:end_time]

  @rules = IceT::Rule::Repository.new
end

Instance Attribute Details

#end_timeObject (readonly)

Returns the value of attribute end_time.



14
15
16
# File 'lib/ice_t/schedule.rb', line 14

def end_time
  @end_time
end

#start_timeObject (readonly)

Returns the value of attribute start_time.



13
14
15
# File 'lib/ice_t/schedule.rb', line 13

def start_time
  @start_time
end

Instance Method Details

#occurrencesObject



27
28
29
30
31
32
33
34
35
36
# File 'lib/ice_t/schedule.rb', line 27

def occurrences
  return [] if @rules.empty?
  
  # TODO: better error message      
  fail('this needs start_time and end_time') if @start_time.nil? && @end_time.nil?

  @rules.collect{ |rule|
    rule.occurrences(@start_time, @end_time)
  }.flatten
end