Class: ScormEngine::Models::CourseConfiguration

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

Instance Attribute Summary collapse

Class Method Summary collapse

Methods inherited from Base

#to_hash

Instance Attribute Details

#settingsHash

Returns:

  • (Hash)


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

def settings
  @settings
end

Class Method Details

.get_settings_from_api(options = {}) ⇒ Hash

Extract and normalize the settings from the API options.

Parameters:

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

    The API options hash

Returns:

  • (Hash)

    A hash of key/value pairs.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/scorm_engine/models/course_configuration.rb', line 26

def self.get_settings_from_api(options = {})
  return {} if options.nil?

  # API v2 uses "settingItems", API v1 uses "configurationItems"
  configuration_items = options["settingItems"] || options["configurationItems"]
  return {} unless configuration_items.respond_to?(:reduce)

  configuration_items.reduce({}) do |m, o|
    # API v2 uses "effectiveValue", API v1 uses "value"
    value = o["effectiveValue"] || o["value"]
    m[o["id"]] = value
    m
  end
end

.new_from_api(options = {}) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/scorm_engine/models/course_configuration.rb', line 9

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

  this.options = options.dup
  this.settings = get_settings_from_api(options)
  this
end