Class: NewStoreApi::Address1

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/new_store_api/models/address1.rb

Overview

A postal address.

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, country = nil, address_line_2 = SKIP, city = SKIP, first_name = SKIP, last_name = SKIP, phone = SKIP, salutation = SKIP, state = SKIP, suffix = SKIP, title = SKIP, zip_code = SKIP) ⇒ Address1

Returns a new instance of Address1.



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/new_store_api/models/address1.rb', line 110

def initialize(address_line_1 = nil, country = nil, address_line_2 = SKIP,
               city = SKIP, first_name = SKIP, last_name = SKIP,
               phone = SKIP, salutation = SKIP, state = SKIP, suffix = SKIP,
               title = SKIP, zip_code = SKIP)
  @address_line_1 = address_line_1
  @address_line_2 = address_line_2 unless address_line_2 == SKIP
  @city = city unless city == SKIP
  @country = country
  @first_name = first_name unless first_name == SKIP
  @last_name = last_name unless last_name == SKIP
  @phone = phone unless phone == SKIP
  @salutation = salutation unless salutation == SKIP
  @state = state unless state == SKIP
  @suffix = suffix unless suffix == SKIP
  @title = title unless title == SKIP
  @zip_code = zip_code unless zip_code == SKIP
end

Instance Attribute Details

#address_line_1String

First line of the street address.

Returns:

  • (String)


14
15
16
# File 'lib/new_store_api/models/address1.rb', line 14

def address_line_1
  @address_line_1
end

#address_line_2String

Second line of the street address.

Returns:

  • (String)


18
19
20
# File 'lib/new_store_api/models/address1.rb', line 18

def address_line_2
  @address_line_2
end

#cityString

City.

Returns:

  • (String)


22
23
24
# File 'lib/new_store_api/models/address1.rb', line 22

def city
  @city
end

#countryString

The code of the country in the ISO ALPHA-2 format.

Returns:

  • (String)


26
27
28
# File 'lib/new_store_api/models/address1.rb', line 26

def country
  @country
end

#first_nameString

First name.

Returns:

  • (String)


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

def first_name
  @first_name
end

#last_nameString

Last name.

Returns:

  • (String)


34
35
36
# File 'lib/new_store_api/models/address1.rb', line 34

def last_name
  @last_name
end

#phoneString

Phone number.

Returns:

  • (String)


38
39
40
# File 'lib/new_store_api/models/address1.rb', line 38

def phone
  @phone
end

#salutationString

e.g. Mr., Ms., Mrs.

Returns:

  • (String)


42
43
44
# File 'lib/new_store_api/models/address1.rb', line 42

def salutation
  @salutation
end

#stateString

State or region.

Returns:

  • (String)


46
47
48
# File 'lib/new_store_api/models/address1.rb', line 46

def state
  @state
end

#suffixString

e.g. Jr., Sr., III.

Returns:

  • (String)


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

def suffix
  @suffix
end

#titleString

e.g. Dr., Prof., Pres.

Returns:

  • (String)


54
55
56
# File 'lib/new_store_api/models/address1.rb', line 54

def title
  @title
end

#zip_codeString

Postal/ZIP code.

Returns:

  • (String)


58
59
60
# File 'lib/new_store_api/models/address1.rb', line 58

def zip_code
  @zip_code
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/new_store_api/models/address1.rb', line 129

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
  country = hash.key?('country') ? hash['country'] : nil
  address_line_2 =
    hash.key?('address_line_2') ? hash['address_line_2'] : SKIP
  city = hash.key?('city') ? hash['city'] : SKIP
  first_name = hash.key?('first_name') ? hash['first_name'] : SKIP
  last_name = hash.key?('last_name') ? hash['last_name'] : SKIP
  phone = hash.key?('phone') ? hash['phone'] : SKIP
  salutation = hash.key?('salutation') ? hash['salutation'] : SKIP
  state = hash.key?('state') ? hash['state'] : SKIP
  suffix = hash.key?('suffix') ? hash['suffix'] : SKIP
  title = hash.key?('title') ? hash['title'] : SKIP
  zip_code = hash.key?('zip_code') ? hash['zip_code'] : SKIP

  # Create object from extracted values.
  Address1.new(address_line_1,
               country,
               address_line_2,
               city,
               first_name,
               last_name,
               phone,
               salutation,
               state,
               suffix,
               title,
               zip_code)
end

.namesObject

A mapping from model property names to API property names.



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/new_store_api/models/address1.rb', line 61

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'] = 'country'
  @_hash['first_name'] = 'first_name'
  @_hash['last_name'] = 'last_name'
  @_hash['phone'] = 'phone'
  @_hash['salutation'] = 'salutation'
  @_hash['state'] = 'state'
  @_hash['suffix'] = 'suffix'
  @_hash['title'] = 'title'
  @_hash['zip_code'] = 'zip_code'
  @_hash
end

.nullablesObject

An array for nullable fields



95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/new_store_api/models/address1.rb', line 95

def self.nullables
  %w[
    address_line_2
    city
    first_name
    last_name
    phone
    salutation
    state
    suffix
    title
    zip_code
  ]
end

.optionalsObject

An array for optional fields



79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/new_store_api/models/address1.rb', line 79

def self.optionals
  %w[
    address_line_2
    city
    first_name
    last_name
    phone
    salutation
    state
    suffix
    title
    zip_code
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:

  • The (Address1 | Hash)

    value against the validation is performed.



165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'lib/new_store_api/models/address1.rb', line 165

def self.validate(value)
  if value.instance_of? self
    return (
      APIHelper.valid_type?(value.address_line_1,
                            ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.country,
                              ->(val) { val.instance_of? String })
    )
  end

  return false unless value.instance_of? Hash

  (
    APIHelper.valid_type?(value['address_line_1'],
                          ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['country'],
                            ->(val) { val.instance_of? String })
  )
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



195
196
197
198
199
200
201
202
# File 'lib/new_store_api/models/address1.rb', line 195

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: #{@country.inspect},"\
  " first_name: #{@first_name.inspect}, last_name: #{@last_name.inspect}, phone:"\
  " #{@phone.inspect}, salutation: #{@salutation.inspect}, state: #{@state.inspect}, suffix:"\
  " #{@suffix.inspect}, title: #{@title.inspect}, zip_code: #{@zip_code.inspect}>"
end

#to_sObject

Provides a human-readable string representation of the object.



186
187
188
189
190
191
192
# File 'lib/new_store_api/models/address1.rb', line 186

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: #{@country}, first_name: #{@first_name}, last_name:"\
  " #{@last_name}, phone: #{@phone}, salutation: #{@salutation}, state: #{@state}, suffix:"\
  " #{@suffix}, title: #{@title}, zip_code: #{@zip_code}>"
end