class OSU::Term

A simple helper class to turn strms into readable human names. It can also determine if an strm took place during quarters, semesters, or during the quarter-to-semester transition. It can also calculate the next strm.

Constants

CENTURIES
FOUR_DIGITS
QUARTER_TO_SEMESTER_STRM

this strm was used to to transition from quarters to semesters

Attributes

strm[R]

Public Class Methods

new(strm:) click to toggle source

Initializes a new OsuTerm based on the strm passed in.

@param args [Hash] A hash of arguments to pass into the constructor. @option args [String] :strm

The osu term's strm number. This number has several requirements:

  1. The strm must be a string that's 4 digits in length.

  2. The first character must be 0 or 1. 0 = 1900-1999, 1 = 2000 and beyond

  3. strm's 2nd and 3rd char represents last two digits of the year

  4. the strm's last digit:

    • quarter: 0 (winter), 2 (Spring), 4 (Summer), or 8 (Autumn)

    • semester: 2 (Spring), 4 (Summer), or 8 (Autumn)

For example, '1152' stands for “Spring 2015”. 1 = 2000 15 = 2015 2 = Spring

@return [OsuTerm] A new OSU::Term object. @raise [ArgumentError] Raised when the strm is malformed.

# File lib/osu_term.rb, line 35
def initialize(strm:)
  strm = strm.to_s
  raise ArgumentError, 'strm must be 4 digits in length' unless FOUR_DIGITS.match?(strm)
  raise ArgumentError, 'strm must start with 0 or 1' unless CENTURIES.match?(strm)

  @strm = strm

  if strm < QUARTER_TO_SEMESTER_STRM
    extend(Quarter)
    raise ArgumentError, 'strm must end in 0, 2, 4, or 8' unless Quarter::SEASONS.match?(strm)
  elsif strm == QUARTER_TO_SEMESTER_STRM
    extend(TransitionTerm)
  else
    extend(Semester)
    raise ArgumentError, 'strm must end in 2, 4, or 8' unless Semester::SEASONS.match?(strm)
  end
end

Public Instance Methods

<=>(other) click to toggle source
# File lib/osu_term.rb, line 81
def <=>(other)
  strm <=> other.strm
rescue NoMethodError
  nil
end
abbr_name() click to toggle source
# File lib/osu_term.rb, line 57
def abbr_name
  names[season_number].fetch(:abbr)
end
abbr_year() click to toggle source
# File lib/osu_term.rb, line 61
def abbr_year
  strm[1..2]
end
abbreviated() click to toggle source
# File lib/osu_term.rb, line 77
def abbreviated
  @abbreviated ||= "#{abbr_name} '#{abbr_year} #{abbr_type}"
end
description() click to toggle source
# File lib/osu_term.rb, line 69
def description
  @description ||= "#{name} #{year} #{type}"
end
name() click to toggle source
# File lib/osu_term.rb, line 53
def name
  names[season_number].fetch(:full)
end
next() click to toggle source
# File lib/osu_term.rb, line 111
def next
  self.class.new(strm: next_strm)
end
next_strm() click to toggle source
# File lib/osu_term.rb, line 87
def next_strm
  if transition_semester?
    '1124'
  else
    next_season_number = next_season.fetch(season_number)

    case season_number
    when 0, 2, 4
      century_and_decade = strm[0..2]

      "#{century_and_decade}#{next_season_number}"
    when 8
      century_indicator = strm[0].to_i
      next_year = decade + 1

      if next_year == 100
        [century_indicator + 1, 0, 0, next_season_number].join
      else
        century_indicator.to_s + next_year.to_s.rjust(2, '0') + next_season_number.to_s
      end
    end
  end
end
to_s() click to toggle source
# File lib/osu_term.rb, line 73
def to_s
  description
end
year() click to toggle source
# File lib/osu_term.rb, line 65
def year
  @year ||= "#{century}#{abbr_year}"
end

Private Instance Methods

century() click to toggle source
# File lib/osu_term.rb, line 124
def century
  @century ||= centuries[strm[0].to_i]
end
decade() click to toggle source
# File lib/osu_term.rb, line 128
def decade
  abbr_year.to_i
end
season_number() click to toggle source
# File lib/osu_term.rb, line 120
def season_number
  @season_number ||= strm[-1].to_i
end