Class: ScormEngine::Models::RegistrationLaunchHistory
- Defined in:
- lib/scorm_engine/models/registration_launch_history.rb
Instance Attribute Summary collapse
-
#completion_status ⇒ String
(COMPLETED, INCOMPLETE, UNKNOWN).
- #exit_time ⇒ Time
-
#id ⇒ String
The external identification of the registration.
- #instance_id ⇒ String
- #last_runtime_update ⇒ Time
- #launch_time ⇒ Time
- #score ⇒ Float
-
#success_status ⇒ String
(FAILED, PASSED, UNKNOWN).
- #total_seconds_tracked ⇒ Integer
Class Method Summary collapse
-
.get_score_from_api(options = {}) ⇒ Float
Extract and normalize the scaled passing score from the API options.
-
.get_total_seconds_tracked_from_api(options = {}) ⇒ Time
Extract and normalize the completed date from the API options.
- .new_from_api(options = {}) ⇒ Object
-
.parse_time(string) ⇒ Time
Extract and convert various time formats.
Methods inherited from Base
Instance Attribute Details
#completion_status ⇒ String
Returns (COMPLETED, INCOMPLETE, UNKNOWN).
27 28 29 |
# File 'lib/scorm_engine/models/registration_launch_history.rb', line 27 def completion_status @completion_status end |
#exit_time ⇒ Time
22 23 24 |
# File 'lib/scorm_engine/models/registration_launch_history.rb', line 22 def exit_time @exit_time end |
#id ⇒ String
The external identification of the registration.
7 8 9 |
# File 'lib/scorm_engine/models/registration_launch_history.rb', line 7 def id @id end |
#instance_id ⇒ String
12 13 14 |
# File 'lib/scorm_engine/models/registration_launch_history.rb', line 12 def instance_id @instance_id end |
#last_runtime_update ⇒ Time
42 43 44 |
# File 'lib/scorm_engine/models/registration_launch_history.rb', line 42 def last_runtime_update @last_runtime_update end |
#launch_time ⇒ Time
17 18 19 |
# File 'lib/scorm_engine/models/registration_launch_history.rb', line 17 def launch_time @launch_time end |
#score ⇒ Float
47 48 49 |
# File 'lib/scorm_engine/models/registration_launch_history.rb', line 47 def score @score end |
#success_status ⇒ String
Returns (FAILED, PASSED, UNKNOWN).
32 33 34 |
# File 'lib/scorm_engine/models/registration_launch_history.rb', line 32 def success_status @success_status end |
#total_seconds_tracked ⇒ Integer
37 38 39 |
# File 'lib/scorm_engine/models/registration_launch_history.rb', line 37 def total_seconds_tracked @total_seconds_tracked end |
Class Method Details
.get_score_from_api(options = {}) ⇒ Float
Extract and normalize the scaled passing score from the API options.
94 95 96 97 98 |
# File 'lib/scorm_engine/models/registration_launch_history.rb', line 94 def self.get_score_from_api( = {}) score = .fetch("score", {})["scaled"] return if score.nil? score.to_f end |
.get_total_seconds_tracked_from_api(options = {}) ⇒ Time
Extract and normalize the completed date from the API options.
110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/scorm_engine/models/registration_launch_history.rb', line 110 def self.get_total_seconds_tracked_from_api( = {}) # 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 = ["totalSecondsTracked"] seconds ||= ["totalSecondsTracked "] score = .fetch("score", {}) seconds ||= score["totalSecondsTracked"] seconds ||= score["totalSecondsTracked "] return if seconds.nil? [seconds.to_f, 0].max end |
.new_from_api(options = {}) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/scorm_engine/models/registration_launch_history.rb', line 49 def self.new_from_api( = {}) this = new this. = .dup this.id = ["id"] this.instance_id = ["instanceId"].to_i this.launch_time = parse_time(["launchTimeUtc"]) this.exit_time = parse_time(["exitTimeUtc"]) this.completion_status = ["completionStatus"]&.upcase this.success_status = ["successStatus"]&.upcase this.last_runtime_update = parse_time(["lastRuntimeUpdateUtc"]) this.score = get_score_from_api() this.total_seconds_tracked = get_total_seconds_tracked_from_api() this end |
.parse_time(string) ⇒ Time
Extract and convert various time formats.
78 79 80 81 82 83 |
# 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 |