Class: UKAcademicCalendar::Term
- Inherits:
-
Object
- Object
- UKAcademicCalendar::Term
- Extended by:
- AbstractClass, Forwardable
- Defined in:
- lib/uk_academic_calendar/term.rb
Overview
Abstract class representing blueprint behaviour for academic terms, bounded by writeable start and end dates
Direct Known Subclasses
Instance Attribute Summary collapse
-
#academic_year ⇒ Integer
readonly
The calendar year within which the term’s academic year starts in.
-
#end_date ⇒ Date
Sets value to @end_date, first going through validation.
-
#season ⇒ Symbol
readonly
The name of the season the term spans.
-
#start_date ⇒ Date
Sets value to @start_date, first going through validation.
Instance Method Summary collapse
-
#all_dates ⇒ SortedSet<Date>
Sorted set of dates making up the term.
-
#each ⇒ Object
Forwards to Range.
-
#eql?(other) ⇒ Boolean
(also: #==)
True if self and other are of the same class, academic_year, and have eql start and end dates.
-
#hash ⇒ Integer
The integer hash value for self.
-
#include? ⇒ Object
Forwards to Range.
- #initialize(academic_year) ⇒ UKAcademicCalendar::AutumnTerm, ... constructor
- #inspect ⇒ Object
-
#to_range ⇒ Range
Range bounded by start and end dates, end inclusive.
-
#to_s ⇒ String
Prettified string describing the term, e.g.
Constructor Details
#initialize(academic_year) ⇒ UKAcademicCalendar::AutumnTerm, ...
27 28 29 30 31 32 |
# File 'lib/uk_academic_calendar/term.rb', line 27 def initialize(academic_year) @academic_year = academic_year @season = extract_season_from_class_name @start_date = nominal_start_date @end_date = nominal_end_date end |
Instance Attribute Details
#academic_year ⇒ Integer (readonly)
Returns the calendar year within which the term’s academic year starts in.
35 36 37 |
# File 'lib/uk_academic_calendar/term.rb', line 35 def academic_year @academic_year end |
#end_date ⇒ Date #end_date=(value) ⇒ Date
Sets value to @end_date, first going through validation
51 52 53 |
# File 'lib/uk_academic_calendar/term.rb', line 51 def end_date @end_date end |
#season ⇒ Symbol (readonly)
Returns the name of the season the term spans.
53 54 55 |
# File 'lib/uk_academic_calendar/term.rb', line 53 def season @season end |
Instance Method Details
#all_dates ⇒ SortedSet<Date>
Returns sorted set of dates making up the term.
94 95 96 |
# File 'lib/uk_academic_calendar/term.rb', line 94 def all_dates SortedSet.new(to_range.to_a) end |
#each ⇒ Object
Forwards to Range
23 |
# File 'lib/uk_academic_calendar/term.rb', line 23 def_delegators :to_range, :include?, :each |
#eql?(other) ⇒ Boolean Also known as: ==
Returns true if self and other are of the same class, academic_year, and have eql start and end dates. Otherwise returns false.
63 64 65 |
# File 'lib/uk_academic_calendar/term.rb', line 63 def eql?(other) hash == other.hash end |
#hash ⇒ Integer
Returns the integer hash value for self.
56 57 58 |
# File 'lib/uk_academic_calendar/term.rb', line 56 def hash [self.class, academic_year, start_date, end_date].hash end |
#include? ⇒ Object
Forwards to Range
23 |
# File 'lib/uk_academic_calendar/term.rb', line 23 def_delegators :to_range, :include?, :each |
#inspect ⇒ Object
76 77 78 |
# File 'lib/uk_academic_calendar/term.rb', line 76 def inspect to_s end |
#to_range ⇒ Range
Returns range bounded by start and end dates, end inclusive.
89 90 91 |
# File 'lib/uk_academic_calendar/term.rb', line 89 def to_range start_date..end_date end |
#to_s ⇒ String
Returns prettified string describing the term, e.g. “Summer 2023/2024”.
72 73 74 |
# File 'lib/uk_academic_calendar/term.rb', line 72 def to_s "#{season.to_s.titleize} #{academic_year.to_s(slash_succ: true)}" end |