Class: WalmartApIs::Address

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

Overview

Address 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(name:, address_line1:, city:, state_or_region:, postal_code:, country_code: 'US', address_line2: SKIP, phone: SKIP, additional_properties: nil) ⇒ Address

Returns a new instance of Address.



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/walmart_ap_is/models/address.rb', line 71

def initialize(name:, address_line1:, city:, state_or_region:, postal_code:,
               country_code: 'US', address_line2: SKIP, phone: SKIP,
               additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @name = name
  @address_line1 = address_line1
  @address_line2 = address_line2 unless address_line2 == SKIP
  @city = city
  @state_or_region = state_or_region
  @postal_code = postal_code
  @country_code = country_code
  @phone = phone unless phone == SKIP
  @additional_properties = additional_properties
end

Instance Attribute Details

#address_line1String

TODO: Write general description for this method

Returns:

  • (String)


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

def address_line1
  @address_line1
end

#address_line2String

TODO: Write general description for this method

Returns:

  • (String)


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

def address_line2
  @address_line2
end

#cityString

TODO: Write general description for this method

Returns:

  • (String)


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

def city
  @city
end

#country_codeString

TODO: Write general description for this method

Returns:

  • (String)


38
39
40
# File 'lib/walmart_ap_is/models/address.rb', line 38

def country_code
  @country_code
end

#nameString

TODO: Write general description for this method

Returns:

  • (String)


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

def name
  @name
end

#phoneString

TODO: Write general description for this method

Returns:

  • (String)


42
43
44
# File 'lib/walmart_ap_is/models/address.rb', line 42

def phone
  @phone
end

#postal_codeString

TODO: Write general description for this method

Returns:

  • (String)


34
35
36
# File 'lib/walmart_ap_is/models/address.rb', line 34

def postal_code
  @postal_code
end

#state_or_regionString

TODO: Write general description for this method

Returns:

  • (String)


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

def state_or_region
  @state_or_region
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/walmart_ap_is/models/address.rb', line 89

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  name = hash.key?('name') ? hash['name'] : nil
  address_line1 = hash.key?('addressLine1') ? hash['addressLine1'] : nil
  city = hash.key?('city') ? hash['city'] : nil
  state_or_region = hash.key?('stateOrRegion') ? hash['stateOrRegion'] : nil
  postal_code = hash.key?('postalCode') ? hash['postalCode'] : nil
  country_code = hash['countryCode'] ||= 'US'
  address_line2 = hash.key?('addressLine2') ? hash['addressLine2'] : SKIP
  phone = hash.key?('phone') ? hash['phone'] : 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.
  Address.new(name: name,
              address_line1: address_line1,
              city: city,
              state_or_region: state_or_region,
              postal_code: postal_code,
              country_code: country_code,
              address_line2: address_line2,
              phone: phone,
              additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/walmart_ap_is/models/address.rb', line 45

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['name'] = 'name'
  @_hash['address_line1'] = 'addressLine1'
  @_hash['address_line2'] = 'addressLine2'
  @_hash['city'] = 'city'
  @_hash['state_or_region'] = 'stateOrRegion'
  @_hash['postal_code'] = 'postalCode'
  @_hash['country_code'] = 'countryCode'
  @_hash['phone'] = 'phone'
  @_hash
end

.nullablesObject

An array for nullable fields



67
68
69
# File 'lib/walmart_ap_is/models/address.rb', line 67

def self.nullables
  []
end

.optionalsObject

An array for optional fields



59
60
61
62
63
64
# File 'lib/walmart_ap_is/models/address.rb', line 59

def self.optionals
  %w[
    address_line2
    phone
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



131
132
133
134
135
136
137
138
# File 'lib/walmart_ap_is/models/address.rb', line 131

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} name: #{@name.inspect}, address_line1: #{@address_line1.inspect},"\
  " address_line2: #{@address_line2.inspect}, city: #{@city.inspect}, state_or_region:"\
  " #{@state_or_region.inspect}, postal_code: #{@postal_code.inspect}, country_code:"\
  " #{@country_code.inspect}, phone: #{@phone.inspect}, additional_properties:"\
  " #{@additional_properties}>"
end

#to_sObject

Provides a human-readable string representation of the object.



122
123
124
125
126
127
128
# File 'lib/walmart_ap_is/models/address.rb', line 122

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} name: #{@name}, address_line1: #{@address_line1}, address_line2:"\
  " #{@address_line2}, city: #{@city}, state_or_region: #{@state_or_region}, postal_code:"\
  " #{@postal_code}, country_code: #{@country_code}, phone: #{@phone}, additional_properties:"\
  " #{@additional_properties}>"
end