Class: ModernTreasury::Address

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/modern_treasury/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(id:, object:, live_mode:, created_at:, updated_at:, line1:, line2:, locality:, region:, postal_code:, country:) ⇒ Address

Returns a new instance of Address.



96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/modern_treasury/models/address.rb', line 96

def initialize(id:, object:, live_mode:, created_at:, updated_at:, line1:,
               line2:, locality:, region:, postal_code:, country:)
  @id = id
  @object = object
  @live_mode = live_mode
  @created_at = created_at
  @updated_at = updated_at
  @line1 = line1
  @line2 = line2
  @locality = locality
  @region = region
  @postal_code = postal_code
  @country = country
end

Instance Attribute Details

#countryString

Country code conforms to [ISO 3166-1 alpha-2]

Returns:

  • (String)


60
61
62
# File 'lib/modern_treasury/models/address.rb', line 60

def country
  @country
end

#created_atDateTime

This field will be true if this object exists in the live environment or false if it exists in the test environment.

Returns:

  • (DateTime)


29
30
31
# File 'lib/modern_treasury/models/address.rb', line 29

def created_at
  @created_at
end

#idUUID | String

TODO: Write general description for this method

Returns:

  • (UUID | String)


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

def id
  @id
end

#line1String

This field will be true if this object exists in the live environment or false if it exists in the test environment.

Returns:

  • (String)


39
40
41
# File 'lib/modern_treasury/models/address.rb', line 39

def line1
  @line1
end

#line2String

This field will be true if this object exists in the live environment or false if it exists in the test environment.

Returns:

  • (String)


44
45
46
# File 'lib/modern_treasury/models/address.rb', line 44

def line2
  @line2
end

#live_modeTrueClass | FalseClass

This field will be true if this object exists in the live environment or false if it exists in the test environment.

Returns:

  • (TrueClass | FalseClass)


24
25
26
# File 'lib/modern_treasury/models/address.rb', line 24

def live_mode
  @live_mode
end

#localityString

Locality or City.

Returns:

  • (String)


48
49
50
# File 'lib/modern_treasury/models/address.rb', line 48

def locality
  @locality
end

#objectString

TODO: Write general description for this method

Returns:

  • (String)


19
20
21
# File 'lib/modern_treasury/models/address.rb', line 19

def object
  @object
end

#postal_codeString

The postal code of the address.

Returns:

  • (String)


56
57
58
# File 'lib/modern_treasury/models/address.rb', line 56

def postal_code
  @postal_code
end

#regionString

Region or State.

Returns:

  • (String)


52
53
54
# File 'lib/modern_treasury/models/address.rb', line 52

def region
  @region
end

#updated_atDateTime

This field will be true if this object exists in the live environment or false if it exists in the test environment.

Returns:

  • (DateTime)


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

def updated_at
  @updated_at
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/modern_treasury/models/address.rb', line 112

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  id = hash.key?('id') ? hash['id'] : nil
  object = hash.key?('object') ? hash['object'] : nil
  live_mode = hash.key?('live_mode') ? hash['live_mode'] : nil
  created_at = if hash.key?('created_at')
                 (DateTimeHelper.from_rfc3339(hash['created_at']) if hash['created_at'])
               end
  updated_at = if hash.key?('updated_at')
                 (DateTimeHelper.from_rfc3339(hash['updated_at']) if hash['updated_at'])
               end
  line1 = hash.key?('line1') ? hash['line1'] : nil
  line2 = hash.key?('line2') ? hash['line2'] : nil
  locality = hash.key?('locality') ? hash['locality'] : nil
  region = hash.key?('region') ? hash['region'] : nil
  postal_code = hash.key?('postal_code') ? hash['postal_code'] : nil
  country = hash.key?('country') ? hash['country'] : nil

  # Create object from extracted values.
  Address.new(id: id,
              object: object,
              live_mode: live_mode,
              created_at: created_at,
              updated_at: updated_at,
              line1: line1,
              line2: line2,
              locality: locality,
              region: region,
              postal_code: postal_code,
              country: country)
end

.namesObject

A mapping from model property names to API property names.



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/modern_treasury/models/address.rb', line 63

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['id'] = 'id'
  @_hash['object'] = 'object'
  @_hash['live_mode'] = 'live_mode'
  @_hash['created_at'] = 'created_at'
  @_hash['updated_at'] = 'updated_at'
  @_hash['line1'] = 'line1'
  @_hash['line2'] = 'line2'
  @_hash['locality'] = 'locality'
  @_hash['region'] = 'region'
  @_hash['postal_code'] = 'postal_code'
  @_hash['country'] = 'country'
  @_hash
end

.nullablesObject

An array for nullable fields



85
86
87
88
89
90
91
92
93
94
# File 'lib/modern_treasury/models/address.rb', line 85

def self.nullables
  %w[
    line1
    line2
    locality
    region
    postal_code
    country
  ]
end

.optionalsObject

An array for optional fields



80
81
82
# File 'lib/modern_treasury/models/address.rb', line 80

def self.optionals
  []
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:

  • The (Address | Hash)

    value against the validation is performed.



156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
# File 'lib/modern_treasury/models/address.rb', line 156

def self.validate(value)
  if value.instance_of? self
    return (
      APIHelper.valid_type?(value.id,
                            ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.object,
                              ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.live_mode,
                              ->(val) { val.instance_of? TrueClass or val.instance_of? FalseClass }) and
        APIHelper.valid_type?(value.created_at,
                              ->(val) { val.instance_of? DateTime }) and
        APIHelper.valid_type?(value.updated_at,
                              ->(val) { val.instance_of? DateTime }) and
        APIHelper.valid_type?(value.line1,
                              ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.line2,
                              ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.locality,
                              ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.region,
                              ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.postal_code,
                              ->(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['id'],
                          ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['object'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['live_mode'],
                            ->(val) { val.instance_of? TrueClass or val.instance_of? FalseClass }) and
      APIHelper.valid_type?(value['created_at'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['updated_at'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['line1'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['line2'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['locality'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['region'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['postal_code'],
                            ->(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.



221
222
223
224
225
226
227
228
# File 'lib/modern_treasury/models/address.rb', line 221

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} id: #{@id.inspect}, object: #{@object.inspect}, live_mode:"\
  " #{@live_mode.inspect}, created_at: #{@created_at.inspect}, updated_at:"\
  " #{@updated_at.inspect}, line1: #{@line1.inspect}, line2: #{@line2.inspect}, locality:"\
  " #{@locality.inspect}, region: #{@region.inspect}, postal_code: #{@postal_code.inspect},"\
  " country: #{@country.inspect}>"
end

#to_custom_created_atObject



146
147
148
# File 'lib/modern_treasury/models/address.rb', line 146

def to_custom_created_at
  DateTimeHelper.to_rfc3339(created_at)
end

#to_custom_updated_atObject



150
151
152
# File 'lib/modern_treasury/models/address.rb', line 150

def to_custom_updated_at
  DateTimeHelper.to_rfc3339(updated_at)
end

#to_sObject

Provides a human-readable string representation of the object.



213
214
215
216
217
218
# File 'lib/modern_treasury/models/address.rb', line 213

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} id: #{@id}, object: #{@object}, live_mode: #{@live_mode}, created_at:"\
  " #{@created_at}, updated_at: #{@updated_at}, line1: #{@line1}, line2: #{@line2}, locality:"\
  " #{@locality}, region: #{@region}, postal_code: #{@postal_code}, country: #{@country}>"
end