class ScormEngine::Models::Registration

rubocop:disable Metrics/AbcSize

Attributes

activity_details[RW]

@attr

@return [ScormEngine::Models::RegistrationActivityDetail]

completed_date[RW]

@attr Time of the learner's first completion of this registration. @return [Time]

course[RW]

@attr

@return [ScormEngine::Models::Course]

created_date[RW]

@attr Time of the creation of this registration. @return [Time]

first_access_date[RW]

@attr Time of the learner's first interaction with this registration. @return [Time]

id[RW]

@attr The external identification of the registration. @return [String]

instance[RW]

@return [String]

last_access_date[RW]

@attr Time of the learner's last interaction with this registration. @return [Time]

learner[RW]

@attr

@return [ScormEngine::Models::Learner]

registration_completion[RW]

@attr Has this registration been completed? @return [String] (UNKNOWN COMPLETED INCOMPLETE)

registration_completion_amount[RW]

@attr A decimal value between 0 and 1 representing the percentage of this course that the learner has completed so far, if known. Note: for learning standards other than SCORM 2004 4th Edition, this value is based on the percentage of activities completed/passed. This means that single-activity courses in those standards will always return either 0 or 1. @return [Float] (Unknown Passed Failed)

registration_success[RW]

@attr Has this registration been passed? @return [String] (Unknown Passed Failed)

score[RW]

@attr Scaled score between 0 and 100. @return [Float]

total_seconds_tracked[RW]

@attr How long the learner spent taking this registration, in seconds. @return [Integer]

updated[RW]

@attr

@return [Time]

Public Class Methods

get_completed_at_from_api(options = {}) click to toggle source

Extract and normalize the completed date from the API options.

@param [Hash] options

The API options hash

@return [Time]

a date/time or nil if undefined.
# File lib/scorm_engine/models/registration.rb, line 180
def self.get_completed_at_from_api(options = {})
  completed_date = options["completedDate"]
  completed_date ||= options.fetch("score", {})["completedDate"]
  return if completed_date.nil?
  Time.parse(completed_date)
end
get_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 [Float]

A float between 0 and 100 or nil if undefined.
# File lib/scorm_engine/models/registration.rb, line 165
def self.get_score_from_api(options = {})
  score = options.fetch("score", {})["scaled"]
  return if score.nil?
  score.to_f
end
new_from_api(options = {}) click to toggle source
# File lib/scorm_engine/models/registration.rb, line 86
def self.new_from_api(options = {})
  this = new

  this.options = options.dup
  this.id = options["id"]
  this.instance = options["instance"]
  this.updated = Time.parse(options["updated"]) if options.key?("updated")
  this.registration_completion = options["registrationCompletion"]&.upcase
  this.registration_success = options["registrationSuccess"]&.upcase
  this.total_seconds_tracked = options["totalSecondsTracked"]&.to_i
  this.first_access_date = Time.parse(options["firstAccessDate"]) if options.key?("firstAccessDate")
  this.last_access_date = Time.parse(options["lastAccessDate"]) if options.key?("lastAccessDate")
  this.created_date = Time.parse(options["createdDate"]) if options.key?("createdDate")
  this.updated = Time.parse(options["updated"]) if options.key?("updated")
  this.registration_completion_amount = options["registrationCompletionAmount"].to_f # Sometimes it returns "NaN"

  this.score = get_score_from_api(options)
  this.completed_date = get_completed_at_from_api(options)

  this.activity_details = RegistrationActivityDetail.new_from_api(options["activityDetails"]) if options.key?("activityDetails")
  this.course = Course.new_from_api(options["course"]) if options.key?("course")
  this.learner = Learner.new_from_api(options["learner"]) if options.key?("learner")

  this
end

Public Instance Methods

complete?() click to toggle source

Has this registration been completed?

@return [Boolean]

Returns true, false or nil if completion status is unknown.
# File lib/scorm_engine/models/registration.rb, line 118
def complete?
  return nil if registration_completion == "UNKNOWN"
  registration_completion == "COMPLETED"
end
failed?() click to toggle source

Has this registration failed?

@return [Boolean]

Returns true, false or nil if success status is unknown.
# File lib/scorm_engine/models/registration.rb, line 151
def failed?
  return nil if registration_success == "UNKNOWN"
  registration_success == "FAILED"
end
incomplete?() click to toggle source

Is this registration incomplete?

@return [Boolean]

Returns true, false or nil if completion status is unknown.
# File lib/scorm_engine/models/registration.rb, line 129
def incomplete?
  return nil if registration_completion == "UNKNOWN"
  registration_completion == "INCOMPLETE"
end
passed?() click to toggle source

Has this registration been passed?

@return [Boolean]

Returns true, false or nil if success status is unknown.
# File lib/scorm_engine/models/registration.rb, line 140
def passed?
  return nil if registration_success == "UNKNOWN"
  registration_success == "PASSED"
end