class OneRoster::Types::Student

Attributes

first_name[R]
last_name[R]
provider[R]
uid[R]

Public Class Methods

new(attributes = {}, client: nil) click to toggle source
# File lib/types/student.rb, line 11
def initialize(attributes = {}, client: nil)
  @uid          = attributes['sourcedId']
  @first_name   = attributes['givenName']
  @last_name    = attributes['familyName']
  @api_username = attributes['username']
  @status       = attributes['status']
  @email        = attributes['email']
  @username     = username(client)
  @provider     = 'oneroster'
end

Public Instance Methods

to_h() click to toggle source
# File lib/types/student.rb, line 28
def to_h
  {
    uid: @uid,
    first_name: @first_name,
    last_name: @last_name,
    username: @username,
    provider: @provider
  }
end
username(client = nil) click to toggle source
# File lib/types/student.rb, line 22
def username(client = nil)
  username_source = client&.username_source

  @username ||= presence(username_from(username_source)) || default_username
end

Private Instance Methods

blank?(field) click to toggle source
# File lib/types/student.rb, line 44
def blank?(field)
  field.nil? || field == ''
end
default_username() click to toggle source
# File lib/types/student.rb, line 67
def default_username
  presence(@api_username) || presence(@email) || @uid
end
presence(field) click to toggle source
# File lib/types/student.rb, line 40
def presence(field)
  field unless blank?(field)
end
username_from(username_source) click to toggle source
# File lib/types/student.rb, line 48
def username_from(username_source)
  return unless presence(username_source)

  source = username_source(username_source)

  presence(instance_variable_get("@#{source}"))
end
username_source(source) click to toggle source

if the username_source is `sourcedId`, we want to return `uid` so we can grab the right instance variable

# File lib/types/student.rb, line 58
def username_source(source)
  case source
  when 'sourcedId' then 'uid'
  when 'username' then 'api_username'
  else
    source
  end
end