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 = {}, client: nil) ⇒ Enrollment

Returns a new instance of Enrollment.



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/types/enrollment.rb', line 14

def initialize(attributes = {}, client: nil)
  @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']
  @begin_date    = presence(attributes['beginDate'])
  @end_date      = presence(attributes['endDate'])
  @client        = client
  @provider      = 'oneroster'
end

Instance Attribute Details

#begin_dateObject (readonly)

Returns the value of attribute begin_date.



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

def begin_date
  @begin_date
end

#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

#end_dateObject (readonly)

Returns the value of attribute end_date.



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

def end_date
  @end_date
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

#in_term?Boolean

Returns:

  • (Boolean)


45
46
47
48
49
50
51
52
# File 'lib/types/enrollment.rb', line 45

def in_term?
  return true unless @client&.only_provision_current_terms
  return true if begin_date.nil? && end_date.nil?
  return Time.parse(begin_date) < Time.now if !begin_date.nil? && end_date.nil?
  return Time.parse(end_date) > Time.now if !end_date.nil? && begin_date.nil?

  Time.parse(begin_date) <= Time.now && Time.parse(end_date) >= Time.now
end

#presence(value) ⇒ Object



63
64
65
# File 'lib/types/enrollment.rb', line 63

def presence(value)
  value unless value.respond_to?(:empty?) && value.empty?
end

#primaryObject



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

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

#student?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/types/enrollment.rb', line 41

def student?
  @role == 'student'
end

#teacher?Boolean

Returns:

  • (Boolean)


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

def teacher?
  @role == 'teacher'
end

#to_hObject



54
55
56
57
58
59
60
61
# File 'lib/types/enrollment.rb', line 54

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

#valid?Boolean

Returns:

  • (Boolean)


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

def valid?
  return true if student?

  teacher?
end