Class: ScormEngine::Models::Dispatch

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

Instance Attribute Summary collapse

Class Method Summary collapse

Methods inherited from Base

#to_hash

Instance Attribute Details

#allow_new_registrationsBoolean

If true, then new registrations can be created for this dispatch.

Returns:

  • (Boolean)


24
25
26
# File 'lib/scorm_engine/models/dispatch.rb', line 24

def allow_new_registrations
  @allow_new_registrations
end

#course_idString

The external identification of the course.

Returns:

  • (String)


19
20
21
# File 'lib/scorm_engine/models/dispatch.rb', line 19

def course_id
  @course_id
end

#destination_idString

The external identification of the destination.

Returns:

  • (String)


14
15
16
# File 'lib/scorm_engine/models/dispatch.rb', line 14

def destination_id
  @destination_id
end

#enabledBoolean

If true, then this dispatch can be launched.

Returns:

  • (Boolean)


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

def enabled
  @enabled
end

#expiration_dateTime

The date after which this dispatch will be disabled as an ISO 8601 string, or “none” for no expiration date.

Returns:

  • (Time)


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

def expiration_date
  @expiration_date
end

#external_configString

Serialized external configuration information to include when launching the dispatched package.

Returns:

  • (String)


59
60
61
# File 'lib/scorm_engine/models/dispatch.rb', line 59

def external_config
  @external_config
end

#idString

The external identification of this dispatch.

Returns:

  • (String)


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

def id
  @id
end

#instancedBoolean

If true, then a new registration instance will be created if the client LMS doesn’t provide launch data for an existing one. Otherwise, the same instance will always be used for the given cmi.learner_id.

Returns:

  • (Boolean)


31
32
33
# File 'lib/scorm_engine/models/dispatch.rb', line 31

def instanced
  @instanced
end

#registration_capInteger

The maximum number of registrations that can be created for this dispatch, where ‘0’ means ‘unlimited registrations’.

Returns:

  • (Integer)


37
38
39
# File 'lib/scorm_engine/models/dispatch.rb', line 37

def registration_cap
  @registration_cap
end

#registration_countInteger

The number of registrations created for this dispatch.

Returns:

  • (Integer)


42
43
44
# File 'lib/scorm_engine/models/dispatch.rb', line 42

def registration_count
  @registration_count
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.



92
93
94
95
96
# File 'lib/scorm_engine/models/dispatch.rb', line 92

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



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/scorm_engine/models/dispatch.rb', line 61

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.registration_count = data["registrationCount"]&.to_i
  this.expiration_date = get_expiration_date(data)
  this.enabled = data["enabled"]
  this.external_config = data["externalConfig"]

  this
end