class ScormEngine::Models::Registration
rubocop:disable Metrics/AbcSize
Attributes
@attr
@return [ScormEngine::Models::RegistrationActivityDetail]
@attr Time of the learner's first completion of this registration. @return [Time]
@attr
@return [ScormEngine::Models::Course]
@attr Time of the creation of this registration. @return [Time]
@attr Time of the learner's first interaction with this registration. @return [Time]
@attr The external identification of the registration. @return [String]
@return [String]
@attr Time of the learner's last interaction with this registration. @return [Time]
@attr
@return [ScormEngine::Models::Learner]
@attr Has this registration been completed? @return [String] (UNKNOWN COMPLETED INCOMPLETE)
@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)
@attr Has this registration been passed? @return [String] (Unknown Passed Failed)
@attr Scaled score between 0 and 100. @return [Float]
@attr How long the learner spent taking this registration, in seconds. @return [Integer]
@attr
@return [Time]
Public Class Methods
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
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
# 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
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
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
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
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