Class: ScormEngine::Models::DispatchRegistrationCount

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

Instance Attribute Summary collapse

Class Method Summary collapse

Methods inherited from Base

#to_hash

Instance Attribute Details

#idString

The external identification of this dispatch.

Returns:

  • (String)

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

def id
  @id
end

#last_reset_atDateTime

The date and time of the last count reset, if any.

Returns:

  • (DateTime)

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

def last_reset_at
  @last_reset_at
end

#registration_countInteger

The registration count for this dispatch.

Returns:

  • (Integer)

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

def registration_count
  @registration_count
end

Class Method Details

.get_last_reset_time(options = {}) ⇒ Time

Extract and normalize the last reset datetime from the API options.

Parameters:

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

    The API options hash

Returns:

  • (Time)

    a date/time or nil if undefined.


41
42
43
44
45
46
# File 'lib/scorm_engine/models/dispatch_registration_count.rb', line 41

def self.get_last_reset_time(options = {})
  time = options["lastResetTime"]
  return if time.nil? || time == "none"

  Time.parse(time)
end

.new_from_api(options = {}) ⇒ Object


21
22
23
24
25
26
27
28
29
30
# File 'lib/scorm_engine/models/dispatch_registration_count.rb', line 21

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

  this.options = options.dup
  this.id = options["id"]
  this.registration_count = options["registrationCount"].to_i
  this.last_reset_at = get_last_reset_time(options)

  this
end