class LUSIAlmaCourseLoader::Reader

Reads course information from LUSI

Constants

PROCESSING_DEPARTMENT

Alma processing department code

TERMS

Alma term codes

Public Class Methods

new(lusi_api = nil, lusi_lookup = nil, *years, **kwargs) click to toggle source

Initializes a new Reader instance @param lusi_api [LUSI::API::Core::API] the LUSI API instance @param lusi_lookup [LUSI::API::Core::Lookup::LookupService] the LUSI

lookup service

@return [void]

Calls superclass method
# File lib/lusi_alma_course_loader/reader.rb, line 172
def initialize(lusi_api = nil, lusi_lookup = nil, *years, **kwargs)
  # Set the LUSI API and lookup properties for use with subsequent methods
  @lusi_api = lusi_api
  @lusi_lookup = lusi_lookup
  super(*years, **kwargs)
  @departments = departments
  @instructor_roles = instructor_roles
end

Public Instance Methods

years(year = nil, years_previous: nil, years_next: nil) click to toggle source

Returns a list of LUSI year instances @param year [LUSI::API::Calendar::Year] the base year (defaults to the

current academic year)

@param years_previous [Integer] the number of years preceding the base

year

@param years_next [Integer] the number of years following the base year

# File lib/lusi_alma_course_loader/reader.rb, line 187
def years(year = nil, years_previous: nil, years_next: nil)
  years_next = years_next.to_i
  years_previous = years_previous.to_i
  result = []
  result.push(*(year.previous(years_previous))) if years_previous > 0
  result.push(*(year.next(years_next))) if years_next > 0
  result
end

Protected Instance Methods

course_cohorts(year, course) click to toggle source

Returns a list of cohorts for the specified course @param year [Integer, String, LUSI::API::Calendar::Year] the course year @param course [LUSI::API::Course::Module] the course @return [Array<LUSI::API::Course::Cohort>] the cohorts for the course

# File lib/lusi_alma_course_loader/reader.rb, line 212
def course_cohorts(year, course)
  # A single VLE space is always associated with a single course cohort
  nil
end
courses(year) click to toggle source

Returns a list of courses for the specified year @param year [Integer, String, LUSI::API::Calendar::Year] the course year @return [Array<LUSI::API::VLE::VLESpace>] the courses for the year

# File lib/lusi_alma_course_loader/reader.rb, line 201
def courses(year)
  year = year_identity(year)
  LUSI::API::VLE::VLESpace.get_instance(@lusi_api, @lusi_lookup,
                                        active_vle_space_only: false,
                                        year_identity: year)
end
current_academic_year() click to toggle source

Returns the current academic year @return [LUSI::API::Calendar::Year] the current academic year

# File lib/lusi_alma_course_loader/reader.rb, line 219
def current_academic_year
  LUSI::API::Calendar::Year.get_current_academic_year(@lusi_api,
                                                      @lusi_lookup)
end
instructors(year, course, cohort) click to toggle source

Returns a list of instructor usernames for the course/cohort @param year [LUSI::API::Calendar::Year] the course year @param course [LUSI::API::Course::Module] the course @param cohort [LUSI::API::Course::Cohort] the course cohort @return [Array<String>] the course instructors

# File lib/lusi_alma_course_loader/reader.rb, line 229
def instructors(year, course, cohort)
  enrolments = instructor_enrolments(year, course, cohort)
  result = enrolments.map(&:username)
  result.uniq!
  result
end
row_data(data, year, course, cohort, instructors) click to toggle source

Populates the CSV row (array) for a specific course/cohort @param data [Array<String>] the CSV row (array) @param year [LUSI::API::Calendar::Year] the course year @param course [LUSI::API::Course::Module] the course @param cohort [LUSI::API::Course::Cohort] the course cohort @param instructors [Array<LUSI::API::Course::StaffModuleEnrolment>] the

course instructors
# File lib/lusi_alma_course_loader/reader.rb, line 243
def row_data(data, year, course, cohort, instructors)
  # The code of the major (administering) department for the course.
  # Department codes are the talis_code of LUSI::API::Organisation::Unit
  institution, faculty, department = org_units(course).map(&:talis_code)
  # Course title
  data[1] = course.display_long_title
  # Term 1-4 (data[5..8]) are left empty
  # Number of participants (data[11]) is left empty
  # Weekly hours (data[12]) is left empty
  # Instructor 1-10 (data[17..26]) are left empty
  # All instructors
  data[27] = instructor_usernames(instructors)
  # Operation (data[28]) is left empty
  row_data_course_id(data, course, cohort)
  row_data_dates(data, course, cohort)
  row_data_departments(data, department)
  row_data_ids(data, course, cohort, institution, faculty)
  row_data_rollover(data, course, cohort)
end
row_data_course_id(data, course, cohort) click to toggle source
# File lib/lusi_alma_course_loader/reader.rb, line 263
def row_data_course_id(data, course, cohort)
  # Course code
  data[0] = course_id(course, cohort)
  # Section ID - not currently used, set a default value for all courses
  data[2] = '1'
end
row_data_dates(data, course, cohort) click to toggle source
# File lib/lusi_alma_course_loader/reader.rb, line 270
def row_data_dates(data, course, cohort)
  # Start date
  data[9] = course.start_date_utc ? course.start_date_utc.strftime('%Y-%m-%d') : nil
  # End date
  data[10] = course.end_date_utc ? course.end_date_utc.strftime('%Y-%m-%d') : nil
  # Year
  data[13] = lusi_year(course.lusi_year_id)
end
row_data_departments(data, department) click to toggle source
# File lib/lusi_alma_course_loader/reader.rb, line 279
def row_data_departments(data, department)
  # Academic departments
  data[3] = department
  # Processing department
  data[4] = PROCESSING_DEPARTMENT
end
row_data_ids(data, course, cohort, institution, faculty) click to toggle source
# File lib/lusi_alma_course_loader/reader.rb, line 286
def row_data_ids(data, course, cohort, institution, faculty)
  # Searchable ID 1
  # - get the course from the short title {course}-{cohort}-{year}
  title = course.display_short_title
  data[14] = if title && title.count('-') > 1
               title.split('-')[0...-2].join('-')
             else
               title
             end
  # Searchable ID 2
  data[15] = faculty
  # Searchable ID 3
  data[16] = institution
end
row_data_rollover(data, course, cohort) click to toggle source
# File lib/lusi_alma_course_loader/reader.rb, line 301
def row_data_rollover(data, course, cohort)
  # Rollover course code
  data[29] = course_id(course, cohort, :rollover)
  # Rollover course section - use the current section ID
  data[30] = data[2]
end
year_identity(year = nil) click to toggle source

Returns the LUSI year identity code for the specified year. If year is not specified, returns the identity of the current academic year

# File lib/lusi_alma_course_loader/reader.rb, line 310
def year_identity(year = nil)
  year ? lusi_year_identity(year) : current_academic_year.identity
end