Class: WalmartApIs::Pallet

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

Overview

Contains information about a pallet used in the inbound plan.

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(package_id:, dimensions: SKIP, quantity: SKIP, stackability: SKIP, weight: SKIP, additional_properties: nil) ⇒ Pallet

Returns a new instance of Pallet.



60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/walmart_ap_is/models/pallet.rb', line 60

def initialize(package_id:, dimensions: SKIP, quantity: SKIP,
               stackability: SKIP, weight: SKIP, additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @dimensions = dimensions unless dimensions == SKIP
  @package_id = package_id
  @quantity = quantity unless quantity == SKIP
  @stackability = stackability unless stackability == SKIP
  @weight = weight unless weight == SKIP
  @additional_properties = additional_properties
end

Instance Attribute Details

#dimensionsDimensions

Measurement of a package's dimensions.

Returns:



14
15
16
# File 'lib/walmart_ap_is/models/pallet.rb', line 14

def dimensions
  @dimensions
end

#package_idString

Primary key to uniquely identify a Package (Box or Pallet).

Returns:

  • (String)


18
19
20
# File 'lib/walmart_ap_is/models/pallet.rb', line 18

def package_id
  @package_id
end

#quantityInteger

The number of containers where all other properties like weight or dimensions are identical.

Returns:

  • (Integer)


23
24
25
# File 'lib/walmart_ap_is/models/pallet.rb', line 23

def quantity
  @quantity
end

#stackabilityStackability

Indicates whether pallets will be stacked when carrier arrives for pick-up.

Returns:



28
29
30
# File 'lib/walmart_ap_is/models/pallet.rb', line 28

def stackability
  @stackability
end

#weightWeight

The weight of a package.

Returns:



32
33
34
# File 'lib/walmart_ap_is/models/pallet.rb', line 32

def weight
  @weight
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/walmart_ap_is/models/pallet.rb', line 74

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  package_id = hash.key?('packageId') ? hash['packageId'] : nil
  dimensions = Dimensions.from_hash(hash['dimensions']) if hash['dimensions']
  quantity = hash.key?('quantity') ? hash['quantity'] : SKIP
  stackability = hash.key?('stackability') ? hash['stackability'] : SKIP
  weight = Weight.from_hash(hash['weight']) if hash['weight']

  # 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.
  Pallet.new(package_id: package_id,
             dimensions: dimensions,
             quantity: quantity,
             stackability: stackability,
             weight: weight,
             additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



35
36
37
38
39
40
41
42
43
# File 'lib/walmart_ap_is/models/pallet.rb', line 35

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['dimensions'] = 'dimensions'
  @_hash['package_id'] = 'packageId'
  @_hash['quantity'] = 'quantity'
  @_hash['stackability'] = 'stackability'
  @_hash['weight'] = 'weight'
  @_hash
end

.nullablesObject

An array for nullable fields



56
57
58
# File 'lib/walmart_ap_is/models/pallet.rb', line 56

def self.nullables
  []
end

.optionalsObject

An array for optional fields



46
47
48
49
50
51
52
53
# File 'lib/walmart_ap_is/models/pallet.rb', line 46

def self.optionals
  %w[
    dimensions
    quantity
    stackability
    weight
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



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

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} dimensions: #{@dimensions.inspect}, package_id: #{@package_id.inspect},"\
  " quantity: #{@quantity.inspect}, stackability: #{@stackability.inspect}, weight:"\
  " #{@weight.inspect}, additional_properties: #{@additional_properties}>"
end

#to_sObject

Provides a human-readable string representation of the object.



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

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} dimensions: #{@dimensions}, package_id: #{@package_id}, quantity:"\
  " #{@quantity}, stackability: #{@stackability}, weight: #{@weight}, additional_properties:"\
  " #{@additional_properties}>"
end