Class: WalmartApIs::Address
- Defined in:
- lib/walmart_ap_is/models/address.rb
Overview
Address Model.
Instance Attribute Summary collapse
-
#address_line1 ⇒ String
TODO: Write general description for this method.
-
#address_line2 ⇒ String
TODO: Write general description for this method.
-
#city ⇒ String
TODO: Write general description for this method.
-
#country_code ⇒ String
TODO: Write general description for this method.
-
#name ⇒ String
TODO: Write general description for this method.
-
#phone ⇒ String
TODO: Write general description for this method.
-
#postal_code ⇒ String
TODO: Write general description for this method.
-
#state_or_region ⇒ String
TODO: Write general description for this method.
Class Method Summary collapse
-
.from_hash(hash) ⇒ Object
Creates an instance of the object from a hash.
-
.names ⇒ Object
A mapping from model property names to API property names.
-
.nullables ⇒ Object
An array for nullable fields.
-
.optionals ⇒ Object
An array for optional fields.
Instance Method Summary collapse
-
#initialize(name:, address_line1:, city:, state_or_region:, postal_code:, country_code: 'US', address_line2: SKIP, phone: SKIP, additional_properties: nil) ⇒ Address
constructor
A new instance of Address.
-
#inspect ⇒ Object
Provides a debugging-friendly string with detailed object information.
-
#to_s ⇒ Object
Provides a human-readable string representation of the object.
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_line1 ⇒ String
TODO: Write general description for this method
18 19 20 |
# File 'lib/walmart_ap_is/models/address.rb', line 18 def address_line1 @address_line1 end |
#address_line2 ⇒ String
TODO: Write general description for this method
22 23 24 |
# File 'lib/walmart_ap_is/models/address.rb', line 22 def address_line2 @address_line2 end |
#city ⇒ String
TODO: Write general description for this method
26 27 28 |
# File 'lib/walmart_ap_is/models/address.rb', line 26 def city @city end |
#country_code ⇒ String
TODO: Write general description for this method
38 39 40 |
# File 'lib/walmart_ap_is/models/address.rb', line 38 def country_code @country_code end |
#name ⇒ String
TODO: Write general description for this method
14 15 16 |
# File 'lib/walmart_ap_is/models/address.rb', line 14 def name @name end |
#phone ⇒ String
TODO: Write general description for this method
42 43 44 |
# File 'lib/walmart_ap_is/models/address.rb', line 42 def phone @phone end |
#postal_code ⇒ String
TODO: Write general description for this method
34 35 36 |
# File 'lib/walmart_ap_is/models/address.rb', line 34 def postal_code @postal_code end |
#state_or_region ⇒ String
TODO: Write general description for this method
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 |
.names ⇒ Object
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 |
.nullables ⇒ Object
An array for nullable fields
67 68 69 |
# File 'lib/walmart_ap_is/models/address.rb', line 67 def self.nullables [] end |
.optionals ⇒ Object
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
#inspect ⇒ Object
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_s ⇒ Object
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 |