Class: ScormEngine::Models::Course
- Inherits:
-
Object
- Object
- ScormEngine::Models::Course
- Defined in:
- lib/scorm_engine/models/course.rb
Instance Attribute Summary collapse
-
#description ⇒ Object
TODO: Not sure we want this to be settable.
-
#id ⇒ Object
TODO: Not sure we want this to be settable.
-
#options ⇒ Object
writeonly
Sets the attribute options.
-
#registration_count ⇒ Object
TODO: Not sure we want this to be settable.
-
#scaled_passing_score ⇒ Object
TODO: Not sure we want this to be settable.
-
#title ⇒ Object
TODO: Not sure we want this to be settable.
-
#updated ⇒ Object
TODO: Not sure we want this to be settable.
-
#version ⇒ Object
TODO: Not sure we want this to be settable.
Class Method Summary collapse
-
.get_scaled_passing_score_from_api(options = {}) ⇒ Integer
Extract and normalize the scaled passing score from the API options.
-
.get_title_from_api(options = {}) ⇒ String
Extract and sanitize the title from the API options.
- .new_from_api(options = {}) ⇒ Object
Instance Attribute Details
#description ⇒ Object
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/course.rb', line 12 def description @description end |
#id ⇒ Object
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/course.rb', line 12 def id @id end |
#options=(value) ⇒ Object
Sets the attribute options
6 7 8 |
# File 'lib/scorm_engine/models/course.rb', line 6 def (value) = value end |
#registration_count ⇒ Object
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/course.rb', line 12 def registration_count @registration_count end |
#scaled_passing_score ⇒ Object
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/course.rb', line 12 def scaled_passing_score @scaled_passing_score end |
#title ⇒ Object
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/course.rb', line 12 def title @title end |
#updated ⇒ Object
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/course.rb', line 12 def updated @updated end |
#version ⇒ Object
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/course.rb', line 12 def version @version end |
Class Method Details
.get_scaled_passing_score_from_api(options = {}) ⇒ Integer
Extract and normalize the scaled passing score from the API options.
56 57 58 59 60 61 62 63 |
# File 'lib/scorm_engine/models/course.rb', line 56 def self.get_scaled_passing_score_from_api( = {}) first_child = .fetch("rootActivity", {}).fetch("children", [{}]).first score = first_child.is_a?(Hash) ? first_child["scaledPassingScore"] : nil return if score.nil? score = score.to_f score *= 100 if score <= 1.0 score.to_i end |
.get_title_from_api(options = {}) ⇒ String
Extract and sanitize the title from the API options.
Special consideration is given to two commonly found, but useless titles which if found will result in a blank title.
41 42 43 44 45 |
# File 'lib/scorm_engine/models/course.rb', line 41 def self.get_title_from_api( = {}) title = ScormEngine::Utils.sanitized_text(["title"]) title = "" if ["Title", "Captivate E-Learning Course"].include?(title) title end |
.new_from_api(options = {}) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/scorm_engine/models/course.rb', line 15 def self.new_from_api( = {}) this = new this. = .dup this.id = ["id"] this.version = ["version"] this.title = get_title_from_api() this.registration_count = ["registrationCount"] this.updated = Time.parse(["updated"]) if .key?("updated") this.description = .fetch("metadata", {})["description"] this.scaled_passing_score = get_scaled_passing_score_from_api() this end |