Class: OneRoster::Types::Enrollment

Inherits:
Base
  • Object
show all
Defined in:
lib/types/enrollment.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Enrollment

Returns a new instance of Enrollment.



12
13
14
15
16
17
18
19
20
# File 'lib/types/enrollment.rb', line 12

def initialize(attributes = {}, *)
  @uid           = attributes['sourcedId']
  # allow instantiation with classroom_uid and user_uid attrs for consistency with clever
  @classroom_uid = attributes['classroom_uid'] || attributes.dig('class', 'sourcedId')
  @user_uid      = attributes['user_uid'] || attributes.dig('user', 'sourcedId')
  @role          = attributes['role']
  @primary       = attributes['primary']
  @provider      = 'oneroster'
end

Instance Attribute Details

#classroom_uidObject (readonly)

Returns the value of attribute classroom_uid.



6
7
8
# File 'lib/types/enrollment.rb', line 6

def classroom_uid
  @classroom_uid
end

#providerObject (readonly)

Returns the value of attribute provider.



6
7
8
# File 'lib/types/enrollment.rb', line 6

def provider
  @provider
end

#roleObject (readonly)

Returns the value of attribute role.



6
7
8
# File 'lib/types/enrollment.rb', line 6

def role
  @role
end

#uidObject (readonly)

Returns the value of attribute uid.



6
7
8
# File 'lib/types/enrollment.rb', line 6

def uid
  @uid
end

#user_uidObject (readonly)

Returns the value of attribute user_uid.



6
7
8
# File 'lib/types/enrollment.rb', line 6

def user_uid
  @user_uid
end

Instance Method Details

#primaryObject



28
29
30
# File 'lib/types/enrollment.rb', line 28

def primary
  teacher? && @primary.to_s == 'true'
end

#student?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/types/enrollment.rb', line 36

def student?
  @role == 'student'
end

#teacher?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/types/enrollment.rb', line 32

def teacher?
  @role == 'teacher'
end

#to_hObject



40
41
42
43
44
45
46
47
# File 'lib/types/enrollment.rb', line 40

def to_h
  {
    classroom_uid: @classroom_uid,
    user_uid: @user_uid,
    primary: primary,
    provider: @provider
  }
end

#valid?Boolean

Returns:

  • (Boolean)


22
23
24
25
26
# File 'lib/types/enrollment.rb', line 22

def valid?
  return true if student?

  teacher?
end