Class: SiriusApi::SemesterDay

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/sirius_api/semester_day.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(period, date, teaching_week) ⇒ SemesterDay

Returns a new instance of SemesterDay.

Parameters:

  • period (SemesterPeriod)

    (see #period)

  • date (Date)

    (see #date)

  • teaching_week (Fixnum, nil)

    (see #teaching_week)


31
32
33
34
35
# File 'lib/sirius_api/semester_day.rb', line 31

def initialize(period, date, teaching_week)
  @period = period
  @date = date.freeze
  @teaching_week = teaching_week
end

Instance Attribute Details

#dateDate (readonly)

Returns:

  • (Date)

9
10
11
# File 'lib/sirius_api/semester_day.rb', line 9

def date
  @date
end

#irregularBoolean (readonly)

Returns whether this day is irregular.

Returns:

  • (Boolean)

    whether this day is irregular.


24
# File 'lib/sirius_api/semester_day.rb', line 24

def_delegator :@period, :irregular

#periodSemesterPeriod (readonly)

Returns:


12
13
14
# File 'lib/sirius_api/semester_day.rb', line 12

def period
  @period
end

#semesterFacultySemester (readonly)

Returns a semester that contains this day.

Returns:


20
# File 'lib/sirius_api/semester_day.rb', line 20

def_delegator :@period, :faculty_semester, :semester

#teaching_weekFixnum? (readonly)

Returns an ordinal number of the teaching week within the semester, or nil if this day isn't inside a regular teaching period.

Returns:

  • (Fixnum, nil)

    an ordinal number of the teaching week within the semester, or nil if this day isn't inside a regular teaching period.


16
17
18
# File 'lib/sirius_api/semester_day.rb', line 16

def teaching_week
  @teaching_week
end

Instance Method Details

#cwdayFixnum

Returns the day of calendar week. It may not be the same as a real calendar day, due to a semester period with day_override.

Returns:

  • (Fixnum)

    the day of calendar week per ISO 8601 (1-7, Monday is 1).


43
44
45
46
47
48
49
50
51
# File 'lib/sirius_api/semester_day.rb', line 43

def cwday
  return @date.cwday unless period.first_day_override

  @cwday ||= begin
    offset = Day.to_numeric(period.first_day_override) - period.starts_at.cwday
    wday = @date.wday + offset
    (wday - 1) % 7 + 1  # convert 0 to 7 (Sunday)
  end
end

#eql?(other) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)

75
76
77
78
79
# File 'lib/sirius_api/semester_day.rb', line 75

def eql?(other)
  %w[class date period teaching_week].all? do |att|
    other.send(att) == self.send(att)
  end
end

#wday_nameSymbol

Returns name of this day.

Returns:

  • (Symbol)

    name of this day.

See Also:


56
57
58
# File 'lib/sirius_api/semester_day.rb', line 56

def wday_name
  Day.from_numeric(cwday)
end

#week_parityString?

Returns a parity of this day within a teaching semester period. If this day is not within a teaching period, the method returns nil.

Unlike the same named method in SiriusApi::SemesterWeek, this one considers even irregular periods!

Returns:

  • (String, nil)

    'even', 'odd', or nil

See Also:


70
71
72
73
# File 'lib/sirius_api/semester_day.rb', line 70

def week_parity
  return @week_parity if defined? @week_parity
  @week_parity = @period.week_parity(@date)
end