Sha256: bd0366ce44e58371c94e6a0a6e936d26508354e8037a9a24612e12ecdbdf57b5

Contents?: true

Size: 1.79 KB

Versions: 7

Compression:

Stored size: 1.79 KB

Contents

# frozen_string_literal: true

module Meibo
  class Enrollment
    ROLES = {
      administrator: 'administrator',
      proctor: 'proctor',
      student: 'student',
      teacher: 'teacher'
    }.freeze

    DataModel.define(
      self,
      attribute_name_to_header_field_map: {
        sourced_id: 'sourcedId',
        status: 'status',
        date_last_modified: 'dateLastModified',
        class_sourced_id: 'classSourcedId',
        school_sourced_id: 'schoolSourcedId',
        user_sourced_id: 'userSourcedId',
        role: 'role',
        primary: 'primary',
        begin_date: 'beginDate',
        end_date: 'endDate'
      }.freeze,
      converters: {
        boolean: [:primary].freeze,
        date: [:begin_date, :end_date].freeze,
        datetime: [:date_last_modified].freeze,
        enum: { role: [*ROLES.values, ENUM_EXT_PATTERN].freeze }.freeze,
        required: [:sourced_id, :class_sourced_id, :school_sourced_id, :user_sourced_id, :role].freeze,
        status: [:status].freeze
      }
    )

    def initialize(sourced_id:, status: nil, date_last_modified: nil, class_sourced_id:, school_sourced_id:, user_sourced_id:, role:, primary: nil, begin_date: nil, end_date: nil, **extension_fields)
      @sourced_id = sourced_id
      @status = status
      @date_last_modified = date_last_modified
      @class_sourced_id = class_sourced_id
      @school_sourced_id = school_sourced_id
      @user_sourced_id = user_sourced_id
      @role = role
      @begin_date = begin_date
      @end_date = end_date
      @extension_fields = extension_fields
    end

    def administrator?
      role == ROLES[:administrator]
    end

    def proctor?
      role == ROLES[:proctor]
    end

    def student?
      role == ROLES[:student]
    end

    def teacher?
      role == ROLES[:teacher]
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
meibo-0.12.0 lib/meibo/enrollment.rb
meibo-0.11.0 lib/meibo/enrollment.rb
meibo-0.10.0 lib/meibo/enrollment.rb
meibo-0.9.0 lib/meibo/enrollment.rb
meibo-0.8.0 lib/meibo/enrollment.rb
meibo-0.7.0 lib/meibo/enrollment.rb
meibo-0.6.0 lib/meibo/enrollment.rb