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



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?



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

def category_level
  @category_level
end

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



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

def cohorts
  @cohorts
end

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



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

def course_departments
  @course_departments
end

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



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

def course_documents
  @course_documents
end

#creditString?



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

def credit
  @credit
end

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



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

def delivery_mode
  @delivery_mode
end

#display_long_titleString?



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

def display_long_title
  @display_long_title
end

#display_short_titleString?



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

def display_short_title
  @display_short_title
end

#enrolled_studentsInteger?



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

def enrolled_students
  @enrolled_students
end

#external_course_identityString?



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

def external_course_identity
  @external_course_identity
end

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



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?



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

def learning_hours
  @learning_hours
end

#mnemonicString?



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

def mnemonic
  @mnemonic
end

#statusString?



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

def status
  @status
end

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



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

def syllabus_rules
  @syllabus_rules
end

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



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

def teaching_institution
  @teaching_institution
end

#titleString?



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

def title
  @title
end

#yearString?



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

Yields:

  • (obj)

    Passes the instance to the block

Yield Parameters:



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.



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



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



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