Class: PlannedSemesterPeriod

Inherits:
RolePlaying::Role
  • Object
show all
Defined in:
app/roles/planned_semester_period.rb

Instance Method Summary collapse

Instance Method Details

#day_offsetObject


22
23
24
25
26
27
28
# File 'app/roles/planned_semester_period.rb', line 22

def day_offset
  if first_day_override
    starts_at.wday - Day.to_numeric(first_day_override)
  else
    0
  end
end

#plan(teaching_time) ⇒ Object


10
11
12
13
14
15
16
17
18
19
20
# File 'app/roles/planned_semester_period.rb', line 10

def plan(teaching_time)
  scheduling_start = combine_date_with_time(
    schedule_start_day(teaching_time.parity),
    teaching_time.starts_at
  )

  schedule = IceCube::Schedule.new(scheduling_start, duration: teaching_time.duration)
  schedule.add_recurrence_rule teaching_time.to_recurrence_rule(day_offset, ends_at)
  occurences = schedule.all_occurrences
  occurences.map { |occurence| Period.new(occurence.to_time, occurence + teaching_time.duration) }
end