module LUSIAlmaCourseLoader::Helpers
Methods for handling LUSI data
Constants
- COURSE_ID_OFFSETS
Course ID year offsets
- INSTRUCTOR_ROLES
LUSI instructor roles
Public Instance Methods
Returns the major department for the course @param course [LUSI::API::Course::Module] the LUSI course module @return [LUSI::API::Course::CourseDepartment] the major department
# File lib/lusi_alma_course_loader/reader.rb, line 32 def course_department(course) return nil unless course && course.course_departments # There should only be one major department course.course_departments.select(&:is_major_department)[0] end
Returns the Moodle course ID for a given course/cohort @param course [LUSI::API::VLE::VLESpace] the course @param cohort [LUSI::API::Course::Cohort] the course cohort @param offset [Integer, Symbol] a numerical year offset or symbol
specifying the number of years from the current course year for which the ID is required. This allows generation of course IDs for years other than the specified course. The following symbols are shorthand for numeric offsets: :previous, :rollover - equivalent to offset: -1 :next - equivalent to offset: 1
@return [String] the Moodle course ID
# File lib/lusi_alma_course_loader/reader.rb, line 49 def course_id(course, cohort, offset = nil) offset = COURSE_ID_OFFSETS[offset] || offset.to_i year = if offset != 0 # Get the year identity lusi_year_identity(course.lusi_year_id, offset: offset) else course.lusi_year_id end if course.space_type == 'SHARED' "lusi-#{course.lusi_vle_space_id}-#{year}" else c = course.vle_space_courses[0] "lusi-#{c.identity.course}-#{year}-#{c.identity.cohort}" end end
Returns the organisation unit for a course department @param course [LUSI::API::Course::Module] the LUSI course module @return [LUSI::API::Organisation::Unit] the organisation unit instance of
the major department for the course
# File lib/lusi_alma_course_loader/reader.rb, line 69 def department(course = nil) dept = course_department(course) dept ? dept.org_unit : nil end
Returns the organisation units from LUSI
# File lib/lusi_alma_course_loader/reader.rb, line 75 def departments return @departments unless @departments.nil? organisation = LUSI::API::Organisation::Organisation.new organisation.load(@lusi_api, in_use_only: false) @departments = {} organisation.each(:department) { |o| @departments[o.talis_code] = o } @departments end
Returns a string row field trimmed to the specified length @param value [String] the field value @param length [Integer] the maximum field length @param empty [Object, nil] the value to return if the field value is nil
or empty
@return [String] the formatted field value
# File lib/lusi_alma_course_loader/reader.rb, line 90 def field(value, length = nil, empty = nil) value = empty if value.nil? || value.empty? length && value ? value[0...length] : value end
Returns a list of instructor enrolments for the course/cohort @param year [LUSI::API::Calendar::Year] the course year @param course [LUSI::API::VLE::VLESpace] the course @param cohort [LUSI::API::Course::Cohort] the course cohort @return [Array<LUSI::API::Course::StaffModuleEnrolment>] the course
instructors
# File lib/lusi_alma_course_loader/reader.rb, line 101 def instructor_enrolments(year, course, cohort) result = [] course.vle_space_courses.each do |c| enrolments = LUSI::API::Course::StaffModuleEnrolment.get_instance( @lusi_api, @lusi_lookup, active_vle_space_only: false, course_identity: c.identity.course, cohort_identity: c.identity.cohort, require_username: true, year_identity: c.identity.year ) e = enrolments.select do |e| @instructor_roles.key?(e.enrolment_role.identity) end result.concat(e) end result end
Returns course instructor roles from the :staff_course_roles lookup table @return [Hash<String, LUSI::API::Person::StaffCourseRole>] the roles
# File lib/lusi_alma_course_loader/reader.rb, line 122 def instructor_roles roles = @lusi_lookup.service(:staff_course_role) return [] if roles.nil? roles.select do |_k, v| INSTRUCTOR_ROLES.include?(v.description.downcase.to_sym) end end
Returns a comma-separated list of instructor usernames @param usernames [Array<String>] the instructor usernames @return [String, nil] the comma-separated list of instructor usernames
# File lib/lusi_alma_course_loader/reader.rb, line 133 def instructor_usernames(usernames) result = usernames.join(',') result.nil? || result.empty? ? nil : result end
Returns the ancestor organisation units of the course's major department @param course [LUSI::API::Course::Module] the LUSI course module @return [Array<LUSI::API::Organisation::Unit>] the organisation units in
furthest-to-nearest order [institution, faculty, dept]
# File lib/lusi_alma_course_loader/reader.rb, line 142 def org_units(course = nil) dept = department(course) result = [] until dept.nil? result.unshift(dept) dept = dept.parent end result end