Class: Sirius::EventPlanner

Inherits:
Object
  • Object
show all
Defined in:
lib/sirius/event_planner.rb

Instance Method Summary collapse

Constructor Details

#initializeEventPlanner


10
11
12
13
# File 'lib/sirius/event_planner.rb', line 10

def initialize
  @sync = Sync[Event, matching_attributes: [:faculty, :source_type, :source_id, :absolute_sequence_number], skip_updating: [:relative_sequence_number]]
  @exceptions = ScheduleException.all
end

Instance Method Details

#apply_exceptions(events) ⇒ Object


30
31
32
# File 'lib/sirius/event_planner.rb', line 30

def apply_exceptions(events)
  events.each { |evt| @exceptions.each { |ex| ex.apply(evt) if ex.affects?(evt) } }
end

#plan_semester(semester) ⇒ Object


15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/sirius/event_planner.rb', line 15

def plan_semester(semester)
  time_converter, semester_periods = create_converters(semester)
  slots_dataset(semester).flat_map do |sl|
    slot = PlannedTimetableSlot.new(sl, time_converter)
    events = semester_periods.flat_map do |semester_period|
      slot.generate_events(semester, semester_period)
    end
    number_events(events)
    apply_exceptions(events)
    @sync.perform(events: events)
    slot.clear_extra_events(events)
    events
  end
end