Class: LUSI::API::Course::ModuleBase Abstract

Inherits:
Object
  • Object
show all
Extended by:
LUSI::API::Core::Endpoint
Defined in:
lib/lusi_api/course.rb

Overview

This class is 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

The abstract base class of Module and SchemeOfStudy

Direct Known Subclasses

Module, SchemeOfStudy

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from LUSI::API::Core::Endpoint

lusi_ws_endpoint, lusi_ws_method, lusi_ws_path, lusi_ws_xml_root

Constructor Details

#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) ⇒ void

Initialises a new ModuleBase instance

Parameters:

  • xml (Nokogiri::XML::Document, Nokogiri::XML::Node) (defaults to: nil)

    the parsed XML root of the module or scheme of study

  • lookup (LUSI::API::Core::Lookup::LookupService, nil) (defaults to: nil)

    the lookup service for object resolution

  • category_level (String, nil) (defaults to: nil)

    the default category

  • cohort (LUSI::API::Course::Cohort, nil) (defaults to: nil)

    the default cohort

  • course_departments (Array<LUSI::API::Course::CourseDepartment>, nil) (defaults to: nil)

    the default course departments

  • course_documents (Array<LUSI::API::Course::CourseDocument>, nil) (defaults to: nil)

    the default course documents

  • credit (String, nil) (defaults to: nil)

    the default credit point value

  • delivery_mode (LUSI::API::Core::Code, nil) (defaults to: nil)

    the default delivery mode

  • display_long_title (String, nil) (defaults to: nil)

    the default long title

  • display_short_title (String, nil) (defaults to: nil)

    the default short title

  • enrolled_students (Integer, nil) (defaults to: nil)

    the default number of enrolled students

  • external_course_identity (String, nil) (defaults to: nil)

    the default external course identity code

  • identity (String, nil) (defaults to: nil)

    the default identity code

  • learning_hours (Integer, nil) (defaults to: nil)

    the default number of learning hours

  • mnemonic (String, nil) (defaults to: nil)

    the default mnemonic

  • subjects (Array<LUSI::API::Course::Subject>, nil) (defaults to: nil)

    the default subjects

  • status (String, nil) (defaults to: nil)

    the default status

  • syllabus_rules (Array<SyllabusRule>, nil) (defaults to: nil)

    the default syllabus rules

  • teaching_institution (LUSI::API::Organisation::Unit, nil) (defaults to: nil)

    the default teaching institution

  • title (String, nil) (defaults to: nil)

    the default title

  • year (String, nil) (defaults to: nil)

    the default year



219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
# 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

Instance Attribute Details

#category_levelString?

Returns the category (e.g. ‘UG’, ‘PG’).

Returns:

  • (String, nil)

    the category (e.g. ‘UG’, ‘PG’)



94
95
96
# File 'lib/lusi_api/course.rb', line 94

def category_level
  @category_level
end

#cohortsArray<LUSI::API::Course::Cohort>?

Returns the list of associated cohorts.

Returns:



98
99
100
# File 'lib/lusi_api/course.rb', line 98

def cohorts
  @cohorts
end

#course_departmentsArray<LUSI::API::Course::CourseDepartment>?

Returns the list of associated course departments.

Returns:



102
103
104
# File 'lib/lusi_api/course.rb', line 102

def course_departments
  @course_departments
end

#course_documentsArray<LUSI::API::Course::CourseDocument>?

Returns the list of associated course documents.

Returns:



106
107
108
# File 'lib/lusi_api/course.rb', line 106

def course_documents
  @course_documents
end

#creditString?

Returns the credit point value.

Returns:

  • (String, nil)

    the credit point value



110
111
112
# File 'lib/lusi_api/course.rb', line 110

def credit
  @credit
end

#delivery_modeLUSI::API::Core::Code?

Returns the mode of delivery.

Returns:



114
115
116
# File 'lib/lusi_api/course.rb', line 114

def delivery_mode
  @delivery_mode
end

#display_long_titleString?

Returns the long course title.

Returns:

  • (String, nil)

    the long course title



118
119
120
# File 'lib/lusi_api/course.rb', line 118

def display_long_title
  @display_long_title
end

#display_short_titleString?

Returns the short course title.

Returns:

  • (String, nil)

    the short course title



122
123
124
# File 'lib/lusi_api/course.rb', line 122

def display_short_title
  @display_short_title
end

#enrolled_studentsInteger?

Returns the number of enrolled students.

Returns:

  • (Integer, nil)

    the number of enrolled students



126
127
128
# File 'lib/lusi_api/course.rb', line 126

def enrolled_students
  @enrolled_students
end

#external_course_identityString?

Returns the external course identity.

Returns:

  • (String, nil)

    the external course identity



130
131
132
# File 'lib/lusi_api/course.rb', line 130

def external_course_identity
  @external_course_identity
end

#identityLUSI::API::Course::Identity?

Returns the course identity.

Returns:



134
135
136
# File 'lib/lusi_api/course.rb', line 134

def identity
  @identity
end

#identity_classObject (readonly)

Returns the value of attribute identity_class.



138
139
140
# File 'lib/lusi_api/course.rb', line 138

def identity_class
  @identity_class
end

#learning_hoursInteger?

Returns the total number of learning hours.

Returns:

  • (Integer, nil)

    the total number of learning hours



142
143
144
# File 'lib/lusi_api/course.rb', line 142

def learning_hours
  @learning_hours
end

#mnemonicString?

Returns the mnemonic for the course.

Returns:

  • (String, nil)

    the mnemonic for the course



146
147
148
# File 'lib/lusi_api/course.rb', line 146

def mnemonic
  @mnemonic
end

#statusString?

Returns the status (‘Live’, ‘Dormant’, ‘Draft’ etc.).

Returns:

  • (String, nil)

    the status (‘Live’, ‘Dormant’, ‘Draft’ etc.)



150
151
152
# File 'lib/lusi_api/course.rb', line 150

def status
  @status
end

#syllabus_rulesArray<LUSI::API::Course::SyllabusRule>?

Returns the list of associated syllabus rules.

Returns:



154
155
156
# File 'lib/lusi_api/course.rb', line 154

def syllabus_rules
  @syllabus_rules
end

#teaching_institutionLUSI::API::Organisation::Unit?

Returns the teaching institution.

Returns:



158
159
160
# File 'lib/lusi_api/course.rb', line 158

def teaching_institution
  @teaching_institution
end

#titleString?

Returns the title.

Returns:

  • (String, nil)

    the title



162
163
164
# File 'lib/lusi_api/course.rb', line 162

def title
  @title
end

#yearString?

Returns the academic year.

Returns:

  • (String, nil)

    the academic year



166
167
168
# File 'lib/lusi_api/course.rb', line 166

def year
  @year
end

Class Method Details

.get_instance(api, lookup = nil, **kwargs) {|obj| ... } ⇒ <Array<LUSI::API::Course::Module, LUSI::API::Course::SchemeOfStudy>] the list of matching instances

Returns an array of instances matching the specified search criteria

Parameters:

Yields:

  • (obj)

    Passes the instance to the block

Yield Parameters:

Returns:



185
186
187
188
189
190
191
192
193
194
# 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) ⇒ Hash<String, String>

Returns a hash of parameters for the LUSI API call. Subclasses may extend or override this method.

Parameters:

  • asp_identity (String, nil)

    return instances matching this academic significant period (ASP)

  • cohort_identity (String, nil)

    return instances matching this cohort identity

  • course_identity (String, nil)

    return instances matching this course identity

  • department_identity (String, nil)

    return instances matching this department identity

  • external_course_identity (String, nil)

    return instances matching this external course identity

  • include_course_documentation (Boolean, nil)

    include course documentation if true, otherwise omit it

  • include_syllabus_rules (Boolean, nil)

    include syllabus rules if true, otherwise omit them

  • live_only (Boolean, nil)

    return only live (active) instances if true, otherwise return all instances

  • teaching_institution_id (String, nil)

    return instances matching this teaching institution

  • year_identity (String, nil)

    return instances matching this year identity

Returns:

  • (Hash<String, String>)

    the parameter hash for the LUSI API call



265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
# 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

Instance Method Details

#enrolment_lookup_indicesObject

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



169
170
171
# File 'lib/lusi_api/course.rb', line 169

def enrolment_lookup_indices
  []
end

#enrolment_lookup_keysArray<String>

Returns an array of enrolment lookup table keys for this module/scheme of study

Returns:

  • (Array<String>)

    the enrolment lookup table keys



175
176
177
# File 'lib/lusi_api/course.rb', line 175

def enrolment_lookup_keys
  self.cohorts.map { |cohort| "#{self.identity.lookup_key}-#{cohort.identity}" }
end

#major_departmentsArray<LUSI::API::Course::CourseDepartment>

Returns the major departments for the module/scheme of study

Returns:



288
289
290
# File 'lib/lusi_api/course.rb', line 288

def major_departments
  self.course_departments.select { |course_department| course_department.is_major_department }
end