class OneRoster::Types::Teacher
Attributes
email[R]
first_name[R]
last_name[R]
provider[R]
uid[R]
Public Class Methods
new(attributes = {}, *, client: nil)
click to toggle source
# File lib/types/teacher.rb, line 12 def initialize(attributes = {}, *, client: nil) @uid = attributes['sourcedId'] @email = attributes['email'] @first_name = attributes['givenName'] @last_name = attributes['familyName'] @api_username = attributes['username'] @username = username(client) @provider = 'oneroster' end
Public Instance Methods
to_h()
click to toggle source
# File lib/types/teacher.rb, line 27 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/types/teacher.rb, line 22 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/types/teacher.rb, line 44 def blank?(field) field.nil? || field == '' end
presence(field)
click to toggle source
# File lib/types/teacher.rb, line 40 def presence(field) field unless blank?(field) end
username_from(username_source)
click to toggle source
# File lib/types/teacher.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/teacher.rb, line 58 def username_source(source) case source when 'sourcedId' then 'uid' when 'username' then 'api_username' else source end end