class OpenStax::Salesforce::Remote::TermYear
Constants
- TERMS
TermYear
strings inSalesforce
look like:2015 - 16 Fall 2015 - 16 Spring
One day in the not-distant future we will probably be adding a Summer term
Attributes
end_year[R]
start_year[R]
term[R]
Public Class Methods
from_string(string)
click to toggle source
# File lib/openstax/salesforce/remote/term_year.rb, line 32 def self.from_string(string) return if string.blank? string.match(/20(\d\d) - (\d\d) (\w+)/).tap do |match| raise(ParseError, "Cannot parse '#{string}' as a TermYear") if match.nil? end term = $3.downcase.to_sym start_year = "20#{$1}".to_i raise "Non-sequential years in TermYear: '#{string}'" if $2.to_i != $1.to_i + 1 new(start_year: start_year, term: term) end
guess_from_created_at(created_at)
click to toggle source
# File lib/openstax/salesforce/remote/term_year.rb, line 19 def self.guess_from_created_at(created_at) spring_to_fall_cutoff = Time.zone.local(created_at.year, 4, 15, 00, 00) fall_to_spring_cutoff = Time.zone.local(created_at.year, 11, 15, 00, 00) if created_at < spring_to_fall_cutoff new(start_year: created_at.year - 1, term: :spring) elsif created_at > fall_to_spring_cutoff new(start_year: created_at.year, term: :spring) else new(start_year: created_at.year, term: :fall) end end
new(start_year:, term:)
click to toggle source
# File lib/openstax/salesforce/remote/term_year.rb, line 12 def initialize(start_year:, term:) raise "Invalid term #{term}" if !TERMS.include?(term) @start_year = start_year @end_year = [:fall, :spring].include?(term) ? start_year + 1 : start_year @term = term end
Public Instance Methods
==(other)
click to toggle source
# File lib/openstax/salesforce/remote/term_year.rb, line 64 def ==(other) to_s == other.to_s end
dup()
click to toggle source
# File lib/openstax/salesforce/remote/term_year.rb, line 72 def dup self.class.new(start_year: start_year, term: term) end
eql?(other)
click to toggle source
# File lib/openstax/salesforce/remote/term_year.rb, line 68 def eql?(other) self == other end
fall?()
click to toggle source
# File lib/openstax/salesforce/remote/term_year.rb, line 56 def fall? :fall == @term end
next()
click to toggle source
# File lib/openstax/salesforce/remote/term_year.rb, line 46 def next fall? ? self.class.new(start_year: start_year, term: :spring) : self.class.new(start_year: start_year + 1, term: :fall) end
spring?()
click to toggle source
# File lib/openstax/salesforce/remote/term_year.rb, line 60 def spring? !fall? end
to_s()
click to toggle source
# File lib/openstax/salesforce/remote/term_year.rb, line 52 def to_s "#{start_year} - #{end_year.to_s[2..3]} #{fall? ? 'Fall' : 'Spring'}" end