class LUSI::API::Course::ModuleBase

The abstract base class of Module and SchemeOfStudy @abstract Subclass and define:

identity_class = the class representing identity
lusi_ws_endpoint = the LUSI API endpoint
lusi_ws_method = the LUSI API method to retrieve instance data
lusi_ws_path = the LUSI API URL path
lusi_ws_xml_root = the root element name of the LUSI API XML response

Attributes

category_level[RW]

@!attribute [rw] category_level

@return [String, nil] the category (e.g. 'UG', 'PG')
cohorts[RW]

@!attribute [rw] cohorts

@return [Array<LUSI::API::Course::Cohort>, nil] the list of associated cohorts
course_departments[RW]

@!attribute [rw] course_departments

@return [Array<LUSI::API::Course::CourseDepartment>, nil] the list of associated course departments
course_documents[RW]

@!attribute [rw] course_documents

@return [Array<LUSI::API::Course::CourseDocument>, nil] the list of associated course documents
credit[RW]

@!attribute [rw] credit

@return [String, nil] the credit point value
delivery_mode[RW]

@!attribute [rw] delivery_mode

@return [LUSI::API::Core::Code, nil] the mode of delivery
display_long_title[RW]

@!attribute [rw] display_long_title

@return [String, nil] the long course title
display_short_title[RW]

@!attribute [rw] display_short_title

@return [String, nil] the short course title
enrolled_students[RW]

@!attribute [rw] enrolled_students

@return [Integer, nil] the number of enrolled students
external_course_identity[RW]

@!attribute [rw] external_course_identity

@return [String, nil] the external course identity
identity[RW]

@!attribute [rw] identity

@return [LUSI::API::Course::Identity, nil] the course identity
identity_class[R]

@!attribute [r] identity_class

@return [Class, nil] the class representing module/scheme of study identity
learning_hours[RW]

@!attribute [rw] learning_hours

@return [Integer, nil] the total number of learning hours
mnemonic[RW]

@!attribute [rw] mnemonic

@return [String, nil] the mnemonic for the course
status[RW]

@!attribute [rw] status

@return [String, nil] the status ('Live', 'Dormant', 'Draft' etc.)
syllabus_rules[RW]

@!attribute [rw] syllabus_rules

@return [Array<LUSI::API::Course::SyllabusRule>, nil] the list of associated syllabus rules
teaching_institution[RW]

@!attribute [rw] teaching_institution

@return [LUSI::API::Organisation::Unit, nil] the teaching institution
title[RW]

@!attribute [rw] title

@return [String, nil] the title
year[RW]

@!attribute [rw] year

@return [String, nil] the academic year

Public Class Methods

get_instance(api, lookup = nil, **kwargs) { |obj| ... } click to toggle source

Returns an array of instances matching the specified search criteria @param api [LUSI::API::Core::API] the LUSI API instance to use for searching @param (see get_instance_params) @return [<Array<LUSI::API::Course::Module, LUSI::API::Course::SchemeOfStudy>] the list of matching instances @yield [obj] Passes the instance to the block @yieldparam obj [LUSI::API::Course::Module, LUSI::API::Course::SchemeOfStudy] the instance

# File lib/lusi_api/course.rb, line 185
def self.get_instance(api, lookup = nil, **kwargs)
  # active_vle_spaces_only: nil)
  params = get_instance_params(**kwargs)
  xml = api.call(self.lusi_ws_path, self.lusi_ws_endpoint, self.lusi_ws_method, **params)
  LUSI::API::Core::XML.xml(xml, "xmlns:#{self.lusi_ws_xml_root}") do |m|
    obj = self.new(m, lookup)
    yield(obj) if block_given?
    obj
  end
end
get_instance_params(**kwargs) click to toggle source

Returns a hash of parameters for the LUSI API call. Subclasses may extend or override this method. @param asp_identity [String, nil] return instances matching this academic significant period (ASP) @param cohort_identity (String, nil) return instances matching this cohort identity @param course_identity [String, nil] return instances matching this course identity @param department_identity (String, nil) return instances matching this department identity @param external_course_identity [String, nil] return instances matching this external course identity @param include_course_documentation [Boolean, nil] include course documentation if true, otherwise omit it @param include_syllabus_rules [Boolean, nil] include syllabus rules if true, otherwise omit them @param live_only [Boolean, nil] return only live (active) instances if true, otherwise return all instances @param teaching_institution_id (String, nil) return instances matching this teaching institution @param year_identity (String, nil) return instances matching this year identity @return [Hash<String, String>] the parameter hash for the LUSI API call

# File lib/lusi_api/course.rb, line 265
def self.get_instance_params(**kwargs)
  result = {
    ASPIdentity: kwargs.fetch(:asp_identity, ''),
    CohortIdentity: kwargs.fetch(:cohort_identity, ''),
    CourseIdentity: kwargs.fetch(:course_identity, ''),
    DepartmentIdentity: kwargs.fetch(:department_identity, ''),
    ExternalCourseIdentity: kwargs.fetch(:external_course_identity, ''),
    IncludeCourseDocumentation: kwargs.fetch(:include_course_documentation, false) ? 'true' : 'false',
    IncludeSyllabusRules: kwargs.fetch(:include_syllabus_rules, false) ? 'true' : 'false',
    LiveOnly: kwargs.fetch(:live_only, true) ? 'true' : 'false',
    TeachingInstitutionId: kwargs.fetch(:teaching_institution_id, ''),
    YearIdentity: kwargs.fetch(:year_identity, '')
  }
  if self.lusi_ws_endpoint == 'General.asmx'
    # The General.asmx endpoint methods GetModuleDetails and GetSchemesOfStudy require an extra parameter
    result[:ActiveVLESpaceOnly] = kwargs.fetch(:active_vle_space_only, true) ? 'true' : 'false'
  end
  result
end
new(xml = nil, lookup = nil, category_level: nil, cohort: nil, course_departments: nil, course_documents: nil, credit: nil, delivery_mode: nil, display_long_title: nil, display_short_title: nil, enrolled_students: nil, external_course_identity: nil, identity: nil, learning_hours: nil, mnemonic: nil, subjects: nil, status: nil, syllabus_rules: nil, teaching_institution: nil, title: nil, year: nil) click to toggle source

Initialises a new ModuleBase instance @param xml [Nokogiri::XML::Document, Nokogiri::XML::Node] the parsed XML root of the module or scheme of study @param lookup [LUSI::API::Core::Lookup::LookupService, nil] the lookup service for object resolution @param category_level [String, nil] the default category @param cohort [LUSI::API::Course::Cohort, nil] the default cohort @param course_departments [Array<LUSI::API::Course::CourseDepartment>, nil] the default course departments @param course_documents [Array<LUSI::API::Course::CourseDocument>, nil] the default course documents @param credit [String, nil] the default credit point value @param delivery_mode [LUSI::API::Core::Code, nil] the default delivery mode @param display_long_title [String, nil] the default long title @param display_short_title [String, nil] the default short title @param enrolled_students [Integer, nil] the default number of enrolled students @param external_course_identity [String, nil] the default external course identity code @param identity [String, nil] the default identity code @param learning_hours [Integer, nil] the default number of learning hours @param mnemonic [String, nil] the default mnemonic @param subjects [Array<LUSI::API::Course::Subject>, nil] the default subjects @param status [String, nil] the default status @param syllabus_rules [Array<SyllabusRule>, nil] the default syllabus rules @param teaching_institution [LUSI::API::Organisation::Unit, nil] the default teaching institution @param title [String, nil] the default title @param year [String, nil] the default year @return [void]

# File lib/lusi_api/course.rb, line 219
def initialize(xml = nil, lookup = nil, category_level: nil, cohort: nil, course_departments: nil,
               course_documents: nil, credit: nil, delivery_mode: nil, display_long_title: nil,
               display_short_title: nil, enrolled_students: nil, external_course_identity: nil, identity: nil,
               learning_hours: nil, mnemonic: nil, subjects: nil, status: nil, syllabus_rules: nil,
               teaching_institution: nil, title: nil, year: nil)
  @category_level = LUSI::API::Core::XML.xml_content_at(xml, 'xmlns:CategoryLevel', category_level)
  @cohorts = LUSI::API::Core::XML.xml(xml, 'xmlns:Cohorts/xmlns:Cohort', cohort) { |c| Cohort.new(c, lookup) }
  @course_departments = LUSI::API::Core::XML.xml(xml, 'xmlns:CourseDepartments/xmlns:CourseDepartment',
                                                 course_departments) { |d| CourseDepartment.new(d, lookup) }
  @course_documents = LUSI::API::Core::XML.xml(xml, 'xmlns:CourseDocuments/xmlns:CourseDocument',
                                               course_documents) { |c| CourseDocument.new(c, lookup) }
  @credit = LUSI::API::Core::XML.xml_content_at(xml, 'xmlns:Credit', credit)
  @delivery_mode = LUSI::API::Core::Code.new(LUSI::API::Core::XML.xml_at(xml, 'xmlns:DeliveryMode',
                                                                         delivery_mode), lookup)
  @display_long_title = LUSI::API::Core::XML.xml_content_at(xml, 'xmlns:DisplayLongTitle', display_long_title)
  @display_short_title = LUSI::API::Core::XML.xml_content_at(xml, 'xmlns:DisplayShortTitle',
                                                             display_short_title)
  @external_course_identity = LUSI::API::Core::XML.xml_content_at(xml, 'xmlns:ExternalCourseIdentity',
                                                                  external_course_identity)
  @identity = Identity.new(LUSI::API::Core::XML.xml_at(xml, 'xmlns:Identity', identity), lookup)
  @learning_hours = LUSI::API::Core::XML.xml_int_at(xml, 'xmlns:LearningHours', learning_hours)
  @mnemonic = LUSI::API::Core::XML.xml_content_at(xml, 'xmlns:Mnemonic', mnemonic)
  @status = LUSI::API::Core::XML.xml_content_at(xml, 'xmlns:Status', status)
  @subjects = LUSI::API::Core::XML.xml(xml, 'xmlns:Subjects/xmlns:Subject', subjects) { |s| Subject.new(s, lookup) }
  @syllabus_rules = LUSI::API::Core::XML.xml(xml, 'xmlns:SyllabusRules/xmlns:SyllabusRule',
                                             syllabus_rules) { |s| SyllabusRule.new(s, lookup) }
  @teaching_institution = LUSI::API::Core::XML.lookup(xml, lookup, :institution,
                                                      'xmlns:TeachingInstitution/xmlns:Identity',
                                                      teaching_institution)
  @title = LUSI::API::Core::XML.xml_content_at(xml, 'xmlns:Title', title)
  @year = LUSI::API::Core::XML.xml_content_at(xml, 'xmlns:Year', year)
end

Protected Class Methods

identity_class() click to toggle source

Returns the class representing module/scheme of study identity @return [Class] the identity class

# File lib/lusi_api/course.rb, line 296
def self.identity_class
  Identity
end
lusi_ws_endpoint() click to toggle source

@see (LUSI::API::Core::Endpoint#lusi_ws_endpoint)

# File lib/lusi_api/course.rb, line 301
def self.lusi_ws_endpoint
  'CourseManager.asmx'
end
lusi_ws_path() click to toggle source

@see (LUSI::API::Core::Endpoint#lusi_ws_path)

# File lib/lusi_api/course.rb, line 306
def self.lusi_ws_path
  'LUSIReference'
end

Public Instance Methods

enrolment_lookup_indices() click to toggle source

Returns an array of enrolment lookup table indices to search for this module/scheme of study

# File lib/lusi_api/course.rb, line 169
def enrolment_lookup_indices
  []
end
enrolment_lookup_keys() click to toggle source

Returns an array of enrolment lookup table keys for this module/scheme of study @return [Array<String>] the enrolment lookup table keys

# File lib/lusi_api/course.rb, line 175
def enrolment_lookup_keys
  self.cohorts.map { |cohort| "#{self.identity.lookup_key}-#{cohort.identity}" }
end
major_departments() click to toggle source

Returns the major departments for the module/scheme of study @return [Array<LUSI::API::Course::CourseDepartment>] the major departments

# File lib/lusi_api/course.rb, line 288
def major_departments
  self.course_departments.select { |course_department| course_department.is_major_department }
end