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_statusObject

TODO: Not sure we want this to be settable. Will depend on how we go about creating/updating records. For now it makes it easier to create instances from API options hash.



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

def completion_status
  @completion_status
end

#exit_timeObject

TODO: Not sure we want this to be settable. Will depend on how we go about creating/updating records. For now it makes it easier to create instances from API options hash.



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

def exit_time
  @exit_time
end

#idObject

TODO: Not sure we want this to be settable. Will depend on how we go about creating/updating records. For now it makes it easier to create instances from API options hash.



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

def id
  @id
end

#instance_idObject

TODO: Not sure we want this to be settable. Will depend on how we go about creating/updating records. For now it makes it easier to create instances from API options hash.



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

def instance_id
  @instance_id
end

#last_runtime_updateObject

TODO: Not sure we want this to be settable. Will depend on how we go about creating/updating records. For now it makes it easier to create instances from API options hash.



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

def last_runtime_update
  @last_runtime_update
end

#launch_timeObject

TODO: Not sure we want this to be settable. Will depend on how we go about creating/updating records. For now it makes it easier to create instances from API options hash.



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

def launch_time
  @launch_time
end

#scoreObject

TODO: Not sure we want this to be settable. Will depend on how we go about creating/updating records. For now it makes it easier to create instances from API options hash.



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

def score
  @score
end

#success_statusObject

TODO: Not sure we want this to be settable. Will depend on how we go about creating/updating records. For now it makes it easier to create instances from API options hash.



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

def success_status
  @success_status
end

#total_seconds_trackedObject

TODO: Not sure we want this to be settable. Will depend on how we go about creating/updating records. For now it makes it easier to create instances from API options hash.



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

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.



61
62
63
64
65
# File 'lib/scorm_engine/models/registration_launch_history.rb', line 61

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.



77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/scorm_engine/models/registration_launch_history.rb', line 77

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



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/scorm_engine/models/registration_launch_history.rb', line 16

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"]
  this.success_status = options["successStatus"]
  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:



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

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