class Clever::Types::Teacher

Attributes

email[R]
first_name[R]
last_name[R]
provider[R]
role[R]
uid[R]

Public Class Methods

new(attributes = {}, *, client: nil) click to toggle source
# File lib/clever/types/teacher.rb, line 13
def initialize(attributes = {}, *, client: nil)
  @district_username = attributes.dig('roles', 'teacher', 'credentials', 'district_username')
  @email             = attributes['email']
  @first_name        = attributes['name']['first']
  @last_name         = attributes['name']['last']
  @provider          = 'clever'
  @sis_id            = attributes.dig('roles', 'teacher', 'sis_id')
  @uid               = attributes['id']
  @username          = username(client)
  @role              = 'teacher'
end

Public Instance Methods

to_h() click to toggle source
# File lib/clever/types/teacher.rb, line 31
def to_h
  {
    uid: @uid,
    email: @email,
    first_name: @first_name,
    last_name: @last_name,
    username: @username,
    provider: @provider
  }
end
username(client = nil) click to toggle source
# File lib/clever/types/teacher.rb, line 25
def username(client = nil)
  username_source = client&.staff_username_source

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

Private Instance Methods

blank?(field) click to toggle source
# File lib/clever/types/teacher.rb, line 54
def blank?(field)
  field.nil? || field == ''
end
presence(field) click to toggle source
# File lib/clever/types/teacher.rb, line 50
def presence(field)
  field unless blank?(field)
end
username_from(username_source) click to toggle source
# File lib/clever/types/teacher.rb, line 44
def username_from(username_source)
  return if blank?(username_source)

  presence(instance_variable_get("@#{username_source}"))
end