Class: ScormEngine::Models::RegistrationLaunchHistory

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

Instance Attribute Summary collapse

Class Method Summary collapse

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.



15
16
17
# File 'lib/scorm_engine/models/registration_launch_history.rb', line 15

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.



15
16
17
# File 'lib/scorm_engine/models/registration_launch_history.rb', line 15

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.



15
16
17
# File 'lib/scorm_engine/models/registration_launch_history.rb', line 15

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.



15
16
17
# File 'lib/scorm_engine/models/registration_launch_history.rb', line 15

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.



15
16
17
# File 'lib/scorm_engine/models/registration_launch_history.rb', line 15

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.



15
16
17
# File 'lib/scorm_engine/models/registration_launch_history.rb', line 15

def launch_time
  @launch_time
end

#options=(value) ⇒ Object

Sets the attribute options

Parameters:

  • value

    the value to set the attribute options to.



9
10
11
# File 'lib/scorm_engine/models/registration_launch_history.rb', line 9

def options=(value)
  @options = value
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.



15
16
17
# File 'lib/scorm_engine/models/registration_launch_history.rb', line 15

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.



15
16
17
# File 'lib/scorm_engine/models/registration_launch_history.rb', line 15

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.



15
16
17
# File 'lib/scorm_engine/models/registration_launch_history.rb', line 15

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.



64
65
66
67
68
# File 'lib/scorm_engine/models/registration_launch_history.rb', line 64

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.



80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/scorm_engine/models/registration_launch_history.rb', line 80

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



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

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:



48
49
50
51
52
53
# File 'lib/scorm_engine/models/registration_launch_history.rb', line 48

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