class OneRoster::Types::Class

Attributes

course_uid[R]
grades[R]
period[R]
provider[R]
subjects[R]
term_id[R]
title[R]
uid[R]

Public Class Methods

new(attributes = {}, *) click to toggle source
# File lib/types/class.rb, line 15
def initialize(attributes = {}, *)
  @uid        = attributes['sourcedId']
  @title      = capitalize(attributes['title'])
  @course_uid = attributes['course']['sourcedId']
  @status     = attributes['status']
  @period     = first_period(attributes) || period_from_code(attributes)
  @grades     = presence(attributes['grades']) || []
  @subjects   = presence(attributes['subjects']) || []
  @term_id    = attributes.dig('terms', 0, 'sourcedId')
  @provider   = 'oneroster'
end

Private Instance Methods

blank?(field) click to toggle source
# File lib/types/class.rb, line 45
def blank?(field)
  field.nil? || field == ''
end
capitalize(string) click to toggle source
# File lib/types/class.rb, line 29
def capitalize(string)
  string.split(' ').map(&:capitalize).join(' ')
end
first_period(attributes) click to toggle source
# File lib/types/class.rb, line 33
def first_period(attributes)
  attributes['periods']&.first
end
period_from_code(attributes) click to toggle source
# File lib/types/class.rb, line 37
def period_from_code(attributes)
  attributes['classCode']&.match(/- Period (\d+) -/) { |m| m[1] }
end
presence(field) click to toggle source
# File lib/types/class.rb, line 41
def presence(field)
  field unless blank?(field)
end