Class: NewStoreApi::Address

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/new_store_api/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(address_line_1 = nil, address_line_2 = nil, city = nil, country_code = nil, first_name = nil, last_name = nil, zip_code = nil, phone = SKIP, state = SKIP) ⇒ Address

Returns a new instance of Address.



88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/new_store_api/models/address.rb', line 88

def initialize(address_line_1 = nil, address_line_2 = nil, city = nil,
               country_code = nil, first_name = nil, last_name = nil,
               zip_code = nil, phone = SKIP, state = SKIP)
  @address_line_1 = address_line_1
  @address_line_2 = address_line_2
  @city = city
  @country_code = country_code
  @first_name = first_name
  @last_name = last_name
  @phone = phone unless phone == SKIP
  @state = state unless state == SKIP
  @zip_code = zip_code
end

Instance Attribute Details

#address_line_1String

some carriers/provider rate might require the value to be set. depending on the use case, you MAY set this to an empty string.

Returns:

  • (String)


15
16
17
# File 'lib/new_store_api/models/address.rb', line 15

def address_line_1
  @address_line_1
end

#address_line_2String

some carriers/provider rate might require the value to be set. depending on the use case, you MAY set this to an empty string.

Returns:

  • (String)


20
21
22
# File 'lib/new_store_api/models/address.rb', line 20

def address_line_2
  @address_line_2
end

#cityString

some carriers/provider rate might require the value to be set. depending on the use case, you MAY set this to an empty string.

Returns:

  • (String)


25
26
27
# File 'lib/new_store_api/models/address.rb', line 25

def city
  @city
end

#country_codeString

some carriers/provider rate might require the value to be set. depending on the use case, you MAY set this to an empty string.

Returns:

  • (String)


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

def country_code
  @country_code
end

#first_nameString

some carriers/provider rate might require the value to be set. depending on the use case, you MAY set this to an empty string.

Returns:

  • (String)


35
36
37
# File 'lib/new_store_api/models/address.rb', line 35

def first_name
  @first_name
end

#last_nameString

some carriers/provider rate might require the value to be set. depending on the use case, you MAY set this to an empty string.

Returns:

  • (String)


40
41
42
# File 'lib/new_store_api/models/address.rb', line 40

def last_name
  @last_name
end

#phoneString

some carriers/provider rate might require the value to be set. depending on the use case, you MAY set this to an empty string.

Returns:

  • (String)


45
46
47
# File 'lib/new_store_api/models/address.rb', line 45

def phone
  @phone
end

#stateString

some carriers/provider rate might require the value to be set. depending on the use case, you MAY set this to an empty string.

Returns:

  • (String)


50
51
52
# File 'lib/new_store_api/models/address.rb', line 50

def state
  @state
end

#zip_codeString

some carriers/provider rate might require the value to be set. depending on the use case, you MAY set this to an empty string.

Returns:

  • (String)


55
56
57
# File 'lib/new_store_api/models/address.rb', line 55

def zip_code
  @zip_code
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/new_store_api/models/address.rb', line 103

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  address_line_1 =
    hash.key?('address_line_1') ? hash['address_line_1'] : nil
  address_line_2 =
    hash.key?('address_line_2') ? hash['address_line_2'] : nil
  city = hash.key?('city') ? hash['city'] : nil
  country_code = hash.key?('country_code') ? hash['country_code'] : nil
  first_name = hash.key?('first_name') ? hash['first_name'] : nil
  last_name = hash.key?('last_name') ? hash['last_name'] : nil
  zip_code = hash.key?('zip_code') ? hash['zip_code'] : nil
  phone = hash.key?('phone') ? hash['phone'] : SKIP
  state = hash.key?('state') ? hash['state'] : SKIP

  # Create object from extracted values.
  Address.new(address_line_1,
              address_line_2,
              city,
              country_code,
              first_name,
              last_name,
              zip_code,
              phone,
              state)
end

.namesObject

A mapping from model property names to API property names.



58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/new_store_api/models/address.rb', line 58

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['address_line_1'] = 'address_line_1'
  @_hash['address_line_2'] = 'address_line_2'
  @_hash['city'] = 'city'
  @_hash['country_code'] = 'country_code'
  @_hash['first_name'] = 'first_name'
  @_hash['last_name'] = 'last_name'
  @_hash['phone'] = 'phone'
  @_hash['state'] = 'state'
  @_hash['zip_code'] = 'zip_code'
  @_hash
end

.nullablesObject

An array for nullable fields



81
82
83
84
85
86
# File 'lib/new_store_api/models/address.rb', line 81

def self.nullables
  %w[
    phone
    state
  ]
end

.optionalsObject

An array for optional fields



73
74
75
76
77
78
# File 'lib/new_store_api/models/address.rb', line 73

def self.optionals
  %w[
    phone
    state
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



140
141
142
143
144
145
146
147
# File 'lib/new_store_api/models/address.rb', line 140

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} address_line_1: #{@address_line_1.inspect}, address_line_2:"\
  " #{@address_line_2.inspect}, city: #{@city.inspect}, country_code:"\
  " #{@country_code.inspect}, first_name: #{@first_name.inspect}, last_name:"\
  " #{@last_name.inspect}, phone: #{@phone.inspect}, state: #{@state.inspect}, zip_code:"\
  " #{@zip_code.inspect}>"
end

#to_sObject

Provides a human-readable string representation of the object.



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

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} address_line_1: #{@address_line_1}, address_line_2: #{@address_line_2},"\
  " city: #{@city}, country_code: #{@country_code}, first_name: #{@first_name}, last_name:"\
  " #{@last_name}, phone: #{@phone}, state: #{@state}, zip_code: #{@zip_code}>"
end