Class: ScormEngine::Models::Dispatch

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#allow_new_registrationsObject

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/dispatch.rb', line 12

def allow_new_registrations
  @allow_new_registrations
end

#course_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/dispatch.rb', line 12

def course_id
  @course_id
end

#destination_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/dispatch.rb', line 12

def destination_id
  @destination_id
end

#expiration_dateObject

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/dispatch.rb', line 12

def expiration_date
  @expiration_date
end

#external_configObject

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/dispatch.rb', line 12

def external_config
  @external_config
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/dispatch.rb', line 12

def id
  @id
end

#instancedObject

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/dispatch.rb', line 12

def instanced
  @instanced
end

#options=(value) ⇒ Object

Sets the attribute options

Parameters:

  • value

    the value to set the attribute options to.



6
7
8
# File 'lib/scorm_engine/models/dispatch.rb', line 6

def options=(value)
  @options = value
end

#registration_capObject

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/dispatch.rb', line 12

def registration_cap
  @registration_cap
end

Class Method Details

.get_expiration_date(options = {}) ⇒ Time

Extract and normalize the expiration date from the API options.

Parameters:

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

    The API options hash

Returns:

  • (Time)

    a date/time or nil if undefined.



44
45
46
47
48
# File 'lib/scorm_engine/models/dispatch.rb', line 44

def self.get_expiration_date(options = {})
  expiration_date = options["expirationDate"]
  return if expiration_date.nil? || expiration_date == "none"
  Time.parse(expiration_date)
end

.new_from_api(options = {}) ⇒ Object



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

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

  this.options = options.dup
  this.id = options["id"]

  # get_dispatches (plural) returns values in a nested 'data' field.
  # get_dispatches (singular) does not.
  data = options["data"] || options
  this.destination_id = data["destinationId"]
  this.course_id = data["courseId"]
  this.allow_new_registrations = data["allowNewRegistrations"]
  this.instanced = data["instanced"]
  this.registration_cap = data["registrationCap"]&.to_i
  this.expiration_date = get_expiration_date(data)
  this.external_config = data["externalConfig"]

  this
end