class ScormEngine::Models::RegistrationLaunchHistory
Attributes
completion_status[RW]
@attr
@return [String] (COMPLETED, INCOMPLETE, UNKNOWN)
exit_time[RW]
@attr
@return [Time]
id[RW]
@attr The external identification of the registration. @return [String]
instance_id[RW]
@attr
@return [String]
last_runtime_update[RW]
@attr
@return [Time]
launch_time[RW]
@attr
@return [Time]
score[RW]
@attr
@return [Float]
success_status[RW]
@attr
@return [String] (FAILED, PASSED, UNKNOWN)
total_seconds_tracked[RW]
@attr
@return [Integer]
Public Class Methods
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_launch_history.rb, line 94 def self.get_score_from_api(options = {}) score = options.fetch("score", {})["scaled"] return if score.nil? score.to_f end
get_total_seconds_tracked_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_launch_history.rb, line 110 def self.get_total_seconds_tracked_from_api(options = {}) # There is a bug in the API that returns a trailing space sometimes. # I swear I also saw `totalSecondsTracked` as part of `score`, but can't find it now. # However, since I intentionally did it I'm going to leave it for now. seconds = options["totalSecondsTracked"] seconds ||= options["totalSecondsTracked "] score = options.fetch("score", {}) seconds ||= score["totalSecondsTracked"] seconds ||= score["totalSecondsTracked "] return if seconds.nil? [seconds.to_f, 0].max end
new_from_api(options = {})
click to toggle source
# File lib/scorm_engine/models/registration_launch_history.rb, line 49 def self.new_from_api(options = {}) this = new this.options = options.dup this.id = options["id"] this.instance_id = options["instanceId"].to_i this.launch_time = parse_time(options["launchTimeUtc"]) this.exit_time = parse_time(options["exitTimeUtc"]) this.completion_status = options["completionStatus"]&.upcase this.success_status = options["successStatus"]&.upcase this.last_runtime_update = parse_time(options["lastRuntimeUpdateUtc"]) this.score = get_score_from_api(options) this.total_seconds_tracked = get_total_seconds_tracked_from_api(options) this end
parse_time(string)
click to toggle source
Extract and convert various time formats.
@see basecamp.com/2819363/projects/15019959/messages/79529838
@param [String] string
The string to be parsed into a time.
@return [Time]
# File lib/scorm_engine/models/registration_launch_history.rb, line 78 def self.parse_time(string) return nil if string.nil? || string.empty? Time.strptime("#{string} UTC", "%m/%d/%Y %H:%M:%S %p %Z") rescue StandardError Time.parse(string) end