Class: ScormEngine::Models::Course

Inherits:
Object
  • Object
show all
Defined in:
lib/scorm_engine/models/course.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#course_learning_standardString

The course’s learning standard.

Returns:

  • (SCORM_11, SCORM_12, SCORM_2004_2ND_EDITION, SCORM_2004_3RD_EDITION, SCORM_2004_4TH_EDITION, AICC, XAPI, CMI5)



18
19
20
# File 'lib/scorm_engine/models/course.rb', line 18

def course_learning_standard
  @course_learning_standard
end

#descriptionObject

TODO: Not sure we want this to be settable. Will depend on how we go about creating/updating records. For now it makes it easier to create instances from API options hash.



12
13
14
# File 'lib/scorm_engine/models/course.rb', line 12

def description
  @description
end

#idObject

TODO: Not sure we want this to be settable. Will depend on how we go about creating/updating records. For now it makes it easier to create instances from API options hash.



12
13
14
# File 'lib/scorm_engine/models/course.rb', line 12

def id
  @id
end

#options=(value) ⇒ Object

Sets the attribute options

Parameters:

  • the value to set the attribute options to.



6
7
8
# File 'lib/scorm_engine/models/course.rb', line 6

def options=(value)
  @options = value
end

#registration_countObject

TODO: Not sure we want this to be settable. Will depend on how we go about creating/updating records. For now it makes it easier to create instances from API options hash.



12
13
14
# File 'lib/scorm_engine/models/course.rb', line 12

def registration_count
  @registration_count
end

#scaled_passing_scoreObject

TODO: Not sure we want this to be settable. Will depend on how we go about creating/updating records. For now it makes it easier to create instances from API options hash.



12
13
14
# File 'lib/scorm_engine/models/course.rb', line 12

def scaled_passing_score
  @scaled_passing_score
end

#titleObject

TODO: Not sure we want this to be settable. Will depend on how we go about creating/updating records. For now it makes it easier to create instances from API options hash.



12
13
14
# File 'lib/scorm_engine/models/course.rb', line 12

def title
  @title
end

#updatedObject

TODO: Not sure we want this to be settable. Will depend on how we go about creating/updating records. For now it makes it easier to create instances from API options hash.



12
13
14
# File 'lib/scorm_engine/models/course.rb', line 12

def updated
  @updated
end

#versionObject

TODO: Not sure we want this to be settable. Will depend on how we go about creating/updating records. For now it makes it easier to create instances from API options hash.



12
13
14
# File 'lib/scorm_engine/models/course.rb', line 12

def version
  @version
end

#web_pathString

The web path at which the course’s contents is hosted. For AICC courses, refer to the href proprety of the child activities as this value will not be available.

Returns:



25
26
27
# File 'lib/scorm_engine/models/course.rb', line 25

def web_path
  @web_path
end

Class Method Details

.get_scaled_passing_score_from_api(options = {}) ⇒ Integer

Extract and normalize the scaled passing score from the API options.

Parameters:

  • (defaults to: {})

    The API options hash

Returns:

  • An integer between 0 and 100 or nil if undefined.



70
71
72
73
74
75
76
77
# File 'lib/scorm_engine/models/course.rb', line 70

def self.get_scaled_passing_score_from_api(options = {})
  first_child = options.fetch("rootActivity", {}).fetch("children", [{}]).first
  score = first_child.is_a?(Hash) ? first_child["scaledPassingScore"] : nil
  return if score.nil?
  score = score.to_f
  score *= 100 if score <= 1.0
  score.to_i
end

.get_title_from_api(options = {}) ⇒ String

Extract and sanitize the title from the API options.

Special consideration is given to two commonly found, but useless titles which if found will result in a blank title.

Parameters:

  • (defaults to: {})

    The API options hash

Returns:



55
56
57
58
59
# File 'lib/scorm_engine/models/course.rb', line 55

def self.get_title_from_api(options = {})
  title = ScormEngine::Utils.sanitized_text(options["title"])
  title = "" if ["Title", "Captivate E-Learning Course"].include?(title)
  title
end

.new_from_api(options = {}) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/scorm_engine/models/course.rb', line 27

def self.new_from_api(options = {})
  this = new

  this.options = options.dup
  this.id = options["id"]
  this.version = options["version"]
  this.title = get_title_from_api(options)
  this.registration_count = options["registrationCount"]
  this.updated = Time.parse(options["updated"]) if options.key?("updated")
  this.description = options.fetch("metadata", {})["description"]
  this.scaled_passing_score = get_scaled_passing_score_from_api(options)
  this.course_learning_standard = options["courseLearningStandard"]
  this.web_path = options["webPath"]

  this
end