Module: SiriusApi::SemesterSchedule

Defined in:
lib/sirius_api/semester_schedule.rb

Class Method Summary collapse

Class Method Details

.resolve_day(date, faculty_id) ⇒ SemesterDay?

Returns a semester day for the given date according to schedule of the specified faculty.

Parameters:

  • date (Date)

    date of the day to return.

  • faculty_id (Fixnum)

    organizational number of the faculty.

Returns:

  • (SemesterDay, nil)

    a semester day, or nil if no data.


68
69
70
71
# File 'lib/sirius_api/semester_schedule.rb', line 68

def resolve_day(date, faculty_id)
  resolve_week(date, faculty_id)
    .then { |week| week.days[date.cwday - 1] }
end

.resolve_days(start_date, end_date, faculty_id) ⇒ Array<SemesterDay>

Returns semester days in the given range according to schedule of the specified faculty.

Parameters:

  • start_date (Date)

    date of the first day to return.

  • end_date (Date)

    date of the last day to return.

  • faculty_id (Fixnum)

    organizational number of the faculty.

Returns:


52
53
54
55
56
57
58
# File 'lib/sirius_api/semester_schedule.rb', line 52

def resolve_days(start_date, end_date, faculty_id)
  resolve_weeks(start_date, end_date, faculty_id)
    .flat_map(&:days)
    .compact
    .drop_while { |day| day.date < start_date }
    .take_while { |day| day.date <= end_date }
end

.resolve_week(date, faculty_id) ⇒ SemesterWeek?

Returns a semester week that occurs at the given date according to schedule of the specified faculty.

Parameters:

  • date (Date)
  • faculty_id (Fixnum)

    organizational number of the faculty.

Returns:

  • (SemesterWeek, nil)

    a semester week, or nil of no data.


39
40
41
# File 'lib/sirius_api/semester_schedule.rb', line 39

def resolve_week(date, faculty_id)
  resolve_weeks(date, date, faculty_id).first
end

.resolve_weeks(start_date, end_date, faculty_id) ⇒ Array<SemesterWeek>

Returns semester weeks in the given range according to schedule of the specified faculty.

Parameters:

  • start_date (Date)

    date of the first week to return (will be rounded to the beginning of the week).

  • end_date (Date)

    date of the last week to retun (will be rounded to the beginning of the week).

  • faculty_id (Fixnum)

    organizational number of the faculty.

Returns:


23
24
25
26
27
28
29
# File 'lib/sirius_api/semester_schedule.rb', line 23

def resolve_weeks(start_date, end_date, faculty_id)
  FacultySemester
    .find_by_date_range_with_periods(start_date, end_date, faculty_id)
    .flat_map do |sem|
      SemesterWeek.resolve_weeks(sem, from: start_date.start_of_week, to: end_date)
    end
end