Class: WalmartApIs::Event

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/walmart_ap_is/models/event.rb

Overview

Event Model.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#check_for_conflict, #process_additional_properties, #process_array, #process_basic_value, #process_hash, #to_hash, #to_json

Constructor Details

#initialize(event_code:, event_time:, location: SKIP, description: SKIP, additional_properties: nil) ⇒ Event

Returns a new instance of Event.



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/walmart_ap_is/models/event.rb', line 56

def initialize(event_code:, event_time:, location: SKIP, description: SKIP,
               additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @event_code = event_code
  @event_time = event_time
  @location = location unless location == SKIP
  @description = description unless description == SKIP
  @additional_properties = additional_properties
end

Instance Attribute Details

#descriptionString

Carrier-normalized event code (e.g. PICKED_UP, OUT_FOR_DELIVERY, DELIVERED, EXCEPTION).

Returns:

  • (String)


31
32
33
# File 'lib/walmart_ap_is/models/event.rb', line 31

def description
  @description
end

#event_codeString

Carrier-normalized event code (e.g. PICKED_UP, OUT_FOR_DELIVERY, DELIVERED, EXCEPTION).

Returns:

  • (String)


16
17
18
# File 'lib/walmart_ap_is/models/event.rb', line 16

def event_code
  @event_code
end

#event_timeDateTime

Carrier-normalized event code (e.g. PICKED_UP, OUT_FOR_DELIVERY, DELIVERED, EXCEPTION).

Returns:

  • (DateTime)


21
22
23
# File 'lib/walmart_ap_is/models/event.rb', line 21

def event_time
  @event_time
end

#locationLocation

Carrier-normalized event code (e.g. PICKED_UP, OUT_FOR_DELIVERY, DELIVERED, EXCEPTION).

Returns:



26
27
28
# File 'lib/walmart_ap_is/models/event.rb', line 26

def location
  @location
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/walmart_ap_is/models/event.rb', line 69

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  event_code = hash.key?('eventCode') ? hash['eventCode'] : nil
  event_time = if hash.key?('eventTime')
                 (DateTimeHelper.from_rfc3339(hash['eventTime']) if hash['eventTime'])
               end
  location = Location.from_hash(hash['location']) if hash['location']
  description = hash.key?('description') ? hash['description'] : SKIP

  # Create a new hash for additional properties, removing known properties.
  new_hash = hash.reject { |k, _| names.value?(k) }

  additional_properties = APIHelper.get_additional_properties(
    new_hash, proc { |value| value }
  )

  # Create object from extracted values.
  Event.new(event_code: event_code,
            event_time: event_time,
            location: location,
            description: description,
            additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



34
35
36
37
38
39
40
41
# File 'lib/walmart_ap_is/models/event.rb', line 34

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['event_code'] = 'eventCode'
  @_hash['event_time'] = 'eventTime'
  @_hash['location'] = 'location'
  @_hash['description'] = 'description'
  @_hash
end

.nullablesObject

An array for nullable fields



52
53
54
# File 'lib/walmart_ap_is/models/event.rb', line 52

def self.nullables
  []
end

.optionalsObject

An array for optional fields



44
45
46
47
48
49
# File 'lib/walmart_ap_is/models/event.rb', line 44

def self.optionals
  %w[
    location
    description
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



108
109
110
111
112
113
# File 'lib/walmart_ap_is/models/event.rb', line 108

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} event_code: #{@event_code.inspect}, event_time: #{@event_time.inspect},"\
  " location: #{@location.inspect}, description: #{@description.inspect},"\
  " additional_properties: #{@additional_properties}>"
end

#to_custom_event_timeObject



95
96
97
# File 'lib/walmart_ap_is/models/event.rb', line 95

def to_custom_event_time
  DateTimeHelper.to_rfc3339(event_time)
end

#to_sObject

Provides a human-readable string representation of the object.



100
101
102
103
104
105
# File 'lib/walmart_ap_is/models/event.rb', line 100

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} event_code: #{@event_code}, event_time: #{@event_time}, location:"\
  " #{@location}, description: #{@description}, additional_properties:"\
  " #{@additional_properties}>"
end