Class: ScormEngine::Models::Registration

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#to_hash

Instance Attribute Details

#activity_detailsScormEngine::Models::RegistrationActivityDetail



63
64
65
# File 'lib/scorm_engine/models/registration.rb', line 63

def activity_details
  @activity_details
end

#completed_dateTime

Time of the learner’s first completion of this registration.

Returns:

  • (Time)


78
79
80
# File 'lib/scorm_engine/models/registration.rb', line 78

def completed_date
  @completed_date
end

#courseScormEngine::Models::Course



53
54
55
# File 'lib/scorm_engine/models/registration.rb', line 53

def course
  @course
end

#created_dateTime

Time of the creation of this registration.

Returns:

  • (Time)


83
84
85
# File 'lib/scorm_engine/models/registration.rb', line 83

def created_date
  @created_date
end

#first_access_dateTime

Time of the learner’s first interaction with this registration.

Returns:

  • (Time)


68
69
70
# File 'lib/scorm_engine/models/registration.rb', line 68

def first_access_date
  @first_access_date
end

#idString

The external identification of the registration.

Returns:

  • (String)


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

def id
  @id
end

#instanceString

Returns:

  • (String)


33
34
35
# File 'lib/scorm_engine/models/registration.rb', line 33

def instance
  @instance
end

#last_access_dateTime

Time of the learner’s last interaction with this registration.

Returns:

  • (Time)


73
74
75
# File 'lib/scorm_engine/models/registration.rb', line 73

def last_access_date
  @last_access_date
end

#learnerScormEngine::Models::Learner



58
59
60
# File 'lib/scorm_engine/models/registration.rb', line 58

def learner
  @learner
end

#registration_completionString

Has this registration been completed?

Returns:

  • (String)

    (UNKNOWN COMPLETED INCOMPLETE)



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

def registration_completion
  @registration_completion
end

#registration_completion_amountFloat

A decimal value between 0 and 1 representing the percentage of this course that the learner has completed so far, if known. Note: for learning standards other than SCORM 2004 4th Edition, this value is based on the percentage of activities completed/passed. This means that single-activity courses in those standards will always return either 0 or 1.

Returns:

  • (Float)

    (Unknown Passed Failed)



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

def registration_completion_amount
  @registration_completion_amount
end

#registration_successString

Has this registration been passed?

Returns:

  • (String)

    (Unknown Passed Failed)



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

def registration_success
  @registration_success
end

#scoreFloat

Scaled score between 0 and 100.

Returns:

  • (Float)


48
49
50
# File 'lib/scorm_engine/models/registration.rb', line 48

def score
  @score
end

#total_seconds_trackedInteger

How long the learner spent taking this registration, in seconds.

Returns:

  • (Integer)


43
44
45
# File 'lib/scorm_engine/models/registration.rb', line 43

def total_seconds_tracked
  @total_seconds_tracked
end

#updatedTime

Returns:

  • (Time)


38
39
40
# File 'lib/scorm_engine/models/registration.rb', line 38

def updated
  @updated
end

Class Method Details

.get_completed_at_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.



179
180
181
182
183
184
# File 'lib/scorm_engine/models/registration.rb', line 179

def self.get_completed_at_from_api(options = {})
  completed_date = options["completedDate"]
  completed_date ||= options.fetch("score", {})["completedDate"]
  return if completed_date.nil?
  Time.parse(completed_date)
end

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



164
165
166
167
168
# File 'lib/scorm_engine/models/registration.rb', line 164

def self.get_score_from_api(options = {})
  score = options.fetch("score", {})["scaled"]
  return if score.nil?
  score.to_f
end

.new_from_api(options = {}) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/scorm_engine/models/registration.rb', line 85

def self.new_from_api(options = {})
  this = new

  this.options = options.dup
  this.id = options["id"]
  this.instance = options["instance"]
  this.updated = Time.parse(options["updated"]) if options.key?("updated")
  this.registration_completion = options["registrationCompletion"]&.upcase
  this.registration_success = options["registrationSuccess"]&.upcase
  this.total_seconds_tracked = options["totalSecondsTracked"]&.to_i
  this.first_access_date = Time.parse(options["firstAccessDate"]) if options.key?("firstAccessDate")
  this.last_access_date = Time.parse(options["lastAccessDate"]) if options.key?("lastAccessDate")
  this.created_date = Time.parse(options["createdDate"]) if options.key?("createdDate")
  this.updated = Time.parse(options["updated"]) if options.key?("updated")
  this.registration_completion_amount = options["registrationCompletionAmount"].to_f # Sometimes it returns "NaN"

  this.score = get_score_from_api(options)
  this.completed_date = get_completed_at_from_api(options)

  this.activity_details = RegistrationActivityDetail.new_from_api(options["activityDetails"]) if options.key?("activityDetails")
  this.course = Course.new_from_api(options["course"]) if options.key?("course")
  this.learner = Learner.new_from_api(options["learner"]) if options.key?("learner")

  this
end

Instance Method Details

#complete?Boolean

Has this registration been completed?

Returns:

  • (Boolean)

    Returns true, false or nil if completion status is unknown.



117
118
119
120
# File 'lib/scorm_engine/models/registration.rb', line 117

def complete?
  return nil if registration_completion == "UNKNOWN"
  registration_completion == "COMPLETED"
end

#failed?Boolean

Has this registration failed?

Returns:

  • (Boolean)

    Returns true, false or nil if success status is unknown.



150
151
152
153
# File 'lib/scorm_engine/models/registration.rb', line 150

def failed?
  return nil if registration_success == "UNKNOWN"
  registration_success == "FAILED"
end

#incomplete?Boolean

Is this registration incomplete?

Returns:

  • (Boolean)

    Returns true, false or nil if completion status is unknown.



128
129
130
131
# File 'lib/scorm_engine/models/registration.rb', line 128

def incomplete?
  return nil if registration_completion == "UNKNOWN"
  registration_completion == "INCOMPLETE"
end

#passed?Boolean

Has this registration been passed?

Returns:

  • (Boolean)

    Returns true, false or nil if success status is unknown.



139
140
141
142
# File 'lib/scorm_engine/models/registration.rb', line 139

def passed?
  return nil if registration_success == "UNKNOWN"
  registration_success == "PASSED"
end