Class: ScormEngine::Models::RegistrationLaunchHistory

Inherits:
Base
  • Object
show all
Defined in:
lib/scorm_engine/models/registration_launch_history.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Methods inherited from Base

#to_hash

Instance Attribute Details

#completion_statusString

Returns (COMPLETED, INCOMPLETE, UNKNOWN).

Returns:

  • (String)

    (COMPLETED, INCOMPLETE, UNKNOWN)



27
28
29
# File 'lib/scorm_engine/models/registration_launch_history.rb', line 27

def completion_status
  @completion_status
end

#exit_timeTime

Returns:

  • (Time)


22
23
24
# File 'lib/scorm_engine/models/registration_launch_history.rb', line 22

def exit_time
  @exit_time
end

#idString

The external identification of the registration.

Returns:

  • (String)


7
8
9
# File 'lib/scorm_engine/models/registration_launch_history.rb', line 7

def id
  @id
end

#instance_idString

Returns:

  • (String)


12
13
14
# File 'lib/scorm_engine/models/registration_launch_history.rb', line 12

def instance_id
  @instance_id
end

#last_runtime_updateTime

Returns:

  • (Time)


42
43
44
# File 'lib/scorm_engine/models/registration_launch_history.rb', line 42

def last_runtime_update
  @last_runtime_update
end

#launch_timeTime

Returns:

  • (Time)


17
18
19
# File 'lib/scorm_engine/models/registration_launch_history.rb', line 17

def launch_time
  @launch_time
end

#scoreFloat

Returns:

  • (Float)


47
48
49
# File 'lib/scorm_engine/models/registration_launch_history.rb', line 47

def score
  @score
end

#success_statusString

Returns (FAILED, PASSED, UNKNOWN).

Returns:

  • (String)

    (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_trackedInteger

Returns:

  • (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.

Parameters:

  • options (Hash) (defaults to: {})

    The API options hash

Returns:

  • (Float)

    A float between 0 and 100 or nil if undefined.



94
95
96
97
98
# 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 = {}) ⇒ Time

Extract and normalize the completed date from the API options.

Parameters:

  • options (Hash) (defaults to: {})

    The API options hash

Returns:

  • (Time)

    a date/time or nil if undefined.



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(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 = {}) ⇒ 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(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) ⇒ Time

Extract and convert various time formats.

Parameters:

  • string (String)

    The string to be parsed into a time.

Returns:

  • (Time)

See Also:



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