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 = {}) ⇒ 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 = {}) ⇒ Enrollment
Returns a new instance of Enrollment.
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/types/enrollment.rb', line 14 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'] @begin_date = presence(attributes['beginDate']) @end_date = presence(attributes['endDate']) @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
44 45 46 47 48 49 50 |
# File 'lib/types/enrollment.rb', line 44 def in_term? 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
61 62 63 |
# File 'lib/types/enrollment.rb', line 61 def presence(value) value unless value.respond_to?(:empty?) && value.empty? end |
#primary ⇒ Object
32 33 34 |
# File 'lib/types/enrollment.rb', line 32 def primary teacher? && @primary.to_s == 'true' end |
#student? ⇒ Boolean
40 41 42 |
# File 'lib/types/enrollment.rb', line 40 def student? @role == 'student' end |
#teacher? ⇒ Boolean
36 37 38 |
# File 'lib/types/enrollment.rb', line 36 def teacher? @role == 'teacher' end |
#to_h ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'lib/types/enrollment.rb', line 52 def to_h { classroom_uid: @classroom_uid, user_uid: @user_uid, primary: primary, provider: @provider } end |
#valid? ⇒ Boolean
26 27 28 29 30 |
# File 'lib/types/enrollment.rb', line 26 def valid? return true if student? teacher? end |