Class: WalmartApIs::Item3

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

Overview

Item3 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(quantity:, description:, unit_price: SKIP, unit_weight: SKIP, seller_sku: SKIP, additional_properties: nil) ⇒ Item3

Returns a new instance of Item3.



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

def initialize(quantity:, description:, unit_price: SKIP, unit_weight: SKIP,
               seller_sku: SKIP, additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @quantity = quantity
  @description = description
  @unit_price = unit_price unless unit_price == SKIP
  @unit_weight = unit_weight unless unit_weight == SKIP
  @seller_sku = seller_sku unless seller_sku == SKIP
  @additional_properties = additional_properties
end

Instance Attribute Details

#descriptionString

TODO: Write general description for this method

Returns:

  • (String)


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

def description
  @description
end

#quantityInteger

TODO: Write general description for this method

Returns:

  • (Integer)


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

def quantity
  @quantity
end

#seller_skuString

TODO: Write general description for this method

Returns:

  • (String)


30
31
32
# File 'lib/walmart_ap_is/models/item3.rb', line 30

def seller_sku
  @seller_sku
end

#unit_priceMoney

TODO: Write general description for this method

Returns:



22
23
24
# File 'lib/walmart_ap_is/models/item3.rb', line 22

def unit_price
  @unit_price
end

#unit_weightWeight

TODO: Write general description for this method

Returns:



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

def unit_weight
  @unit_weight
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



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

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  quantity = hash.key?('quantity') ? hash['quantity'] : nil
  description = hash.key?('description') ? hash['description'] : nil
  unit_price = Money.from_hash(hash['unitPrice']) if hash['unitPrice']
  unit_weight = Weight.from_hash(hash['unitWeight']) if hash['unitWeight']
  seller_sku = hash.key?('sellerSku') ? hash['sellerSku'] : 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.
  Item3.new(quantity: quantity,
            description: description,
            unit_price: unit_price,
            unit_weight: unit_weight,
            seller_sku: seller_sku,
            additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



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

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['quantity'] = 'quantity'
  @_hash['description'] = 'description'
  @_hash['unit_price'] = 'unitPrice'
  @_hash['unit_weight'] = 'unitWeight'
  @_hash['seller_sku'] = 'sellerSku'
  @_hash
end

.nullablesObject

An array for nullable fields



53
54
55
# File 'lib/walmart_ap_is/models/item3.rb', line 53

def self.nullables
  []
end

.optionalsObject

An array for optional fields



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

def self.optionals
  %w[
    unit_price
    unit_weight
    seller_sku
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



106
107
108
109
110
111
# File 'lib/walmart_ap_is/models/item3.rb', line 106

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} quantity: #{@quantity.inspect}, description: #{@description.inspect},"\
  " unit_price: #{@unit_price.inspect}, unit_weight: #{@unit_weight.inspect}, seller_sku:"\
  " #{@seller_sku.inspect}, additional_properties: #{@additional_properties}>"
end

#to_sObject

Provides a human-readable string representation of the object.



98
99
100
101
102
103
# File 'lib/walmart_ap_is/models/item3.rb', line 98

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} quantity: #{@quantity}, description: #{@description}, unit_price:"\
  " #{@unit_price}, unit_weight: #{@unit_weight}, seller_sku: #{@seller_sku},"\
  " additional_properties: #{@additional_properties}>"
end