class ScormEngine::Models::Course

Attributes

course_learning_standard[RW]

@attr The course's learning standard. @return [String] (SCORM_11, SCORM_12, SCORM_2004_2ND_EDITION, SCORM_2004_3RD_EDITION, SCORM_2004_4TH_EDITION, AICC, XAPI, CMI5)

description[RW]

@attr The description of this course. @return [String]

id[RW]

@attr The external identification of this course. @return [String]

registration_count[RW]

@attr

@return [Integer]

scaled_passing_score[RW]

@attr The score required of a learner to pass this course. @return [Integer]

title[RW]

@attr The title of this course. @return [String]

updated[RW]

@attr

@return [Time]

version[RW]

@attr The version of this course. @return [Integer]

web_path[RW]

@attr 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. @return [String]

Public Class Methods

get_scaled_passing_score_from_api(options = {}) click to toggle source

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

@param [Hash] options

The API options hash

@return [Integer]

An integer between 0 and 100 or nil if undefined.
# File lib/scorm_engine/models/course.rb, line 96
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 = {}) click to toggle source

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.

@param [Hash] options

The API options hash

@return [String]

# File lib/scorm_engine/models/course.rb, line 81
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 = {}) click to toggle source
# File lib/scorm_engine/models/course.rb, line 53
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"]&.upcase
  this.web_path = options["webPath"]

  this
end