Class: OneRoster::Types::Enrollment
- Defined in:
- lib/types/enrollment.rb
Instance Attribute Summary collapse
-
#begin_date ⇒ Object
readonly
Returns the value of attribute begin_date.
-
#classroom_uid ⇒ Object
readonly
Returns the value of attribute classroom_uid.
-
#end_date ⇒ Object
readonly
Returns the value of attribute end_date.
-
#provider ⇒ Object
readonly
Returns the value of attribute provider.
-
#role ⇒ Object
readonly
Returns the value of attribute role.
-
#uid ⇒ Object
readonly
Returns the value of attribute uid.
-
#user_uid ⇒ Object
readonly
Returns the value of attribute user_uid.
Instance Method Summary collapse
- #in_term? ⇒ Boolean
-
#initialize(attributes = {}, client: nil) ⇒ Enrollment
constructor
A new instance of Enrollment.
- #presence(value) ⇒ Object
- #primary ⇒ Object
- #student? ⇒ Boolean
- #teacher? ⇒ Boolean
- #to_h ⇒ Object
- #valid? ⇒ Boolean
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_date ⇒ Object (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_uid ⇒ Object (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_date ⇒ Object (readonly)
Returns the value of attribute end_date.
6 7 8 |
# File 'lib/types/enrollment.rb', line 6 def end_date @end_date end |
#provider ⇒ Object (readonly)
Returns the value of attribute provider.
6 7 8 |
# File 'lib/types/enrollment.rb', line 6 def provider @provider end |
#role ⇒ Object (readonly)
Returns the value of attribute role.
6 7 8 |
# File 'lib/types/enrollment.rb', line 6 def role @role end |
#uid ⇒ Object (readonly)
Returns the value of attribute uid.
6 7 8 |
# File 'lib/types/enrollment.rb', line 6 def uid @uid end |
#user_uid ⇒ Object (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
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 |
#primary ⇒ Object
33 34 35 |
# File 'lib/types/enrollment.rb', line 33 def primary teacher? && @primary.to_s == 'true' end |
#student? ⇒ Boolean
41 42 43 |
# File 'lib/types/enrollment.rb', line 41 def student? @role == 'student' end |
#teacher? ⇒ Boolean
37 38 39 |
# File 'lib/types/enrollment.rb', line 37 def teacher? @role == 'teacher' end |
#to_h ⇒ Object
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
27 28 29 30 31 |
# File 'lib/types/enrollment.rb', line 27 def valid? return true if student? teacher? end |