Class: YNAB::Account

Inherits:
Object
  • Object
show all
Defined in:
lib/ynab/models/account.rb

Defined Under Namespace

Classes: EnumAttributeValidator

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Account

Initializes the object

Parameters:

  • attributes (Hash) (defaults to: {})

    Model attributes in the form of hash



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
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
# File 'lib/ynab/models/account.rb', line 105

def initialize(attributes = {})
  return unless attributes.is_a?(Hash)

  # convert string to symbol for hash key
  attributes = attributes.each_with_object({}) { |(k, v), h| h[k.to_sym] = v }

  if attributes.has_key?(:'id')
    self.id = attributes[:'id']
  end

  if attributes.has_key?(:'name')
    self.name = attributes[:'name']
  end

  if attributes.has_key?(:'type')
    self.type = attributes[:'type']
  end

  if attributes.has_key?(:'on_budget')
    self.on_budget = attributes[:'on_budget']
  end

  if attributes.has_key?(:'closed')
    self.closed = attributes[:'closed']
  end

  if attributes.has_key?(:'note')
    self.note = attributes[:'note']
  end

  if attributes.has_key?(:'balance')
    self.balance = attributes[:'balance']
  end

  if attributes.has_key?(:'cleared_balance')
    self.cleared_balance = attributes[:'cleared_balance']
  end

  if attributes.has_key?(:'uncleared_balance')
    self.uncleared_balance = attributes[:'uncleared_balance']
  end

  if attributes.has_key?(:'transfer_payee_id')
    self.transfer_payee_id = attributes[:'transfer_payee_id']
  end

  if attributes.has_key?(:'deleted')
    self.deleted = attributes[:'deleted']
  end
end

Instance Attribute Details

#balanceObject

The current balance of the account in milliunits format



33
34
35
# File 'lib/ynab/models/account.rb', line 33

def balance
  @balance
end

#cleared_balanceObject

The current cleared balance of the account in milliunits format



36
37
38
# File 'lib/ynab/models/account.rb', line 36

def cleared_balance
  @cleared_balance
end

#closedObject

Whether this account is closed or not



28
29
30
# File 'lib/ynab/models/account.rb', line 28

def closed
  @closed
end

#deletedObject

Whether or not the account has been deleted. Deleted accounts will only be included in delta requests.



45
46
47
# File 'lib/ynab/models/account.rb', line 45

def deleted
  @deleted
end

#idObject

Returns the value of attribute id.



17
18
19
# File 'lib/ynab/models/account.rb', line 17

def id
  @id
end

#nameObject

Returns the value of attribute name.



19
20
21
# File 'lib/ynab/models/account.rb', line 19

def name
  @name
end

#noteObject

Returns the value of attribute note.



30
31
32
# File 'lib/ynab/models/account.rb', line 30

def note
  @note
end

#on_budgetObject

Whether this account is on budget or not



25
26
27
# File 'lib/ynab/models/account.rb', line 25

def on_budget
  @on_budget
end

#transfer_payee_idObject

The payee id which should be used when transferring to this account



42
43
44
# File 'lib/ynab/models/account.rb', line 42

def transfer_payee_id
  @transfer_payee_id
end

#typeObject

The type of account. Note: payPal, merchantAccount, investmentAccount, and mortgage types have been deprecated and will be removed in the future.



22
23
24
# File 'lib/ynab/models/account.rb', line 22

def type
  @type
end

#uncleared_balanceObject

The current uncleared balance of the account in milliunits format



39
40
41
# File 'lib/ynab/models/account.rb', line 39

def uncleared_balance
  @uncleared_balance
end

Class Method Details

.attribute_mapObject

Attribute mapping from ruby-style variable name to JSON key.



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/ynab/models/account.rb', line 70

def self.attribute_map
  {
    :'id' => :'id',
    :'name' => :'name',
    :'type' => :'type',
    :'on_budget' => :'on_budget',
    :'closed' => :'closed',
    :'note' => :'note',
    :'balance' => :'balance',
    :'cleared_balance' => :'cleared_balance',
    :'uncleared_balance' => :'uncleared_balance',
    :'transfer_payee_id' => :'transfer_payee_id',
    :'deleted' => :'deleted'
  }
end

.swagger_typesObject

Attribute type mapping.



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/ynab/models/account.rb', line 87

def self.swagger_types
  {
    :'id' => :'String',
    :'name' => :'String',
    :'type' => :'String',
    :'on_budget' => :'BOOLEAN',
    :'closed' => :'BOOLEAN',
    :'note' => :'String',
    :'balance' => :'Integer',
    :'cleared_balance' => :'Integer',
    :'uncleared_balance' => :'Integer',
    :'transfer_payee_id' => :'String',
    :'deleted' => :'BOOLEAN'
  }
end

Instance Method Details

#==(o) ⇒ Object

Checks equality by comparing each attribute.

Parameters:

  • Object (Object)

    to be compared



238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
# File 'lib/ynab/models/account.rb', line 238

def ==(o)
  return true if self.equal?(o)
  self.class == o.class &&
      id == o.id &&
      name == o.name &&
      type == o.type &&
      on_budget == o.on_budget &&
      closed == o.closed &&
      note == o.note &&
      balance == o.balance &&
      cleared_balance == o.cleared_balance &&
      uncleared_balance == o.uncleared_balance &&
      transfer_payee_id == o.transfer_payee_id &&
      deleted == o.deleted
end

#_deserialize(type, value) ⇒ Object

Deserializes the data based on type

Parameters:

  • string

    type Data type

  • string

    value Value to be deserialized

Returns:

  • (Object)

    Deserialized data



290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
# File 'lib/ynab/models/account.rb', line 290

def _deserialize(type, value)
  case type.to_sym
  when :DateTime
    DateTime.parse(value)
  when :Date
    Date.parse(value)
  when :String
    value.to_s
  when :Integer
    value.to_i
  when :Float
    value.to_f
  when :BOOLEAN
    if value.to_s =~ /\A(true|t|yes|y|1)\z/i
      true
    else
      false
    end
  when :Object
    # generic object (usually a Hash), return directly
    value
  when /\AArray<(?<inner_type>.+)>\z/
    inner_type = Regexp.last_match[:inner_type]
    value.map { |v| _deserialize(inner_type, v) }
  when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
    k_type = Regexp.last_match[:k_type]
    v_type = Regexp.last_match[:v_type]
    {}.tap do |hash|
      value.each do |k, v|
        hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
      end
    end
  else # model
    temp_model = YNAB.const_get(type).new
    temp_model.build_from_hash(value)
  end
end

#_to_hash(value) ⇒ Hash

Outputs non-array value in the form of hash For object, use to_hash. Otherwise, just return the value

Parameters:

  • value (Object)

    Any valid value

Returns:

  • (Hash)

    Returns the value in the form of hash



356
357
358
359
360
361
362
363
364
365
366
367
368
# File 'lib/ynab/models/account.rb', line 356

def _to_hash(value)
  if value.is_a?(Array)
    value.compact.map { |v| _to_hash(v) }
  elsif value.is_a?(Hash)
    {}.tap do |hash|
      value.each { |k, v| hash[k] = _to_hash(v) }
    end
  elsif value.respond_to? :to_hash
    value.to_hash
  else
    value
  end
end

#build_from_hash(attributes) ⇒ Object

Builds the object from hash

Parameters:

  • attributes (Hash)

    Model attributes in the form of hash

Returns:

  • (Object)

    Returns the model itself



269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
# File 'lib/ynab/models/account.rb', line 269

def build_from_hash(attributes)
  return nil unless attributes.is_a?(Hash)
  self.class.swagger_types.each_pair do |key, type|
    if type =~ /\AArray<(.*)>/i
      # check to ensure the input is an array given that the the attribute
      # is documented as an array but the input is not
      if attributes[self.class.attribute_map[key]].is_a?(Array)
        self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
      end
    elsif !attributes[self.class.attribute_map[key]].nil?
      self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
    end # or else data not found in attributes(hash), not an issue as the data can be optional
  end

  self
end

#eql?(o) ⇒ Boolean

Parameters:

  • Object (Object)

    to be compared

Returns:

  • (Boolean)

See Also:

  • `==` method


256
257
258
# File 'lib/ynab/models/account.rb', line 256

def eql?(o)
  self == o
end

#hashFixnum

Calculates hash code according to all attributes.

Returns:

  • (Fixnum)

    Hash code



262
263
264
# File 'lib/ynab/models/account.rb', line 262

def hash
  [id, name, type, on_budget, closed, note, balance, cleared_balance, uncleared_balance, transfer_payee_id, deleted].hash
end

#list_invalid_propertiesObject

Show invalid properties with the reasons. Usually used together with valid?

Returns:

  • Array for valid properties with the reasons



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
# File 'lib/ynab/models/account.rb', line 158

def list_invalid_properties
  invalid_properties = Array.new
  if @id.nil?
    invalid_properties.push('invalid value for "id", id cannot be nil.')
  end

  if @name.nil?
    invalid_properties.push('invalid value for "name", name cannot be nil.')
  end

  if @type.nil?
    invalid_properties.push('invalid value for "type", type cannot be nil.')
  end

  if @on_budget.nil?
    invalid_properties.push('invalid value for "on_budget", on_budget cannot be nil.')
  end

  if @closed.nil?
    invalid_properties.push('invalid value for "closed", closed cannot be nil.')
  end

  if @note.nil?
    invalid_properties.push('invalid value for "note", note cannot be nil.')
  end

  if @balance.nil?
    invalid_properties.push('invalid value for "balance", balance cannot be nil.')
  end

  if @cleared_balance.nil?
    invalid_properties.push('invalid value for "cleared_balance", cleared_balance cannot be nil.')
  end

  if @uncleared_balance.nil?
    invalid_properties.push('invalid value for "uncleared_balance", uncleared_balance cannot be nil.')
  end

  if @transfer_payee_id.nil?
    invalid_properties.push('invalid value for "transfer_payee_id", transfer_payee_id cannot be nil.')
  end

  if @deleted.nil?
    invalid_properties.push('invalid value for "deleted", deleted cannot be nil.')
  end

  invalid_properties
end

#to_bodyHash

to_body is an alias to to_hash (backward compatibility)

Returns:

  • (Hash)

    Returns the object in the form of hash



336
337
338
# File 'lib/ynab/models/account.rb', line 336

def to_body
  to_hash
end

#to_hashHash

Returns the object in the form of hash

Returns:

  • (Hash)

    Returns the object in the form of hash



342
343
344
345
346
347
348
349
350
# File 'lib/ynab/models/account.rb', line 342

def to_hash
  hash = {}
  self.class.attribute_map.each_pair do |attr, param|
    value = self.send(attr)
    next if value.nil?
    hash[param] = _to_hash(value)
  end
  hash
end

#to_sString

Returns the string representation of the object

Returns:

  • (String)

    String presentation of the object



330
331
332
# File 'lib/ynab/models/account.rb', line 330

def to_s
  to_hash.to_s
end

#valid?Boolean

Check to see if the all the properties in the model are valid

Returns:

  • (Boolean)

    true if the model is valid



209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
# File 'lib/ynab/models/account.rb', line 209

def valid?
  return false if @id.nil?
  return false if @name.nil?
  return false if @type.nil?
  type_validator = EnumAttributeValidator.new('String', ['checking', 'savings', 'cash', 'creditCard', 'lineOfCredit', 'otherAsset', 'otherLiability', 'payPal', 'merchantAccount', 'investmentAccount', 'mortgage'])
  return false unless type_validator.valid?(@type)
  return false if @on_budget.nil?
  return false if @closed.nil?
  return false if @note.nil?
  return false if @balance.nil?
  return false if @cleared_balance.nil?
  return false if @uncleared_balance.nil?
  return false if @transfer_payee_id.nil?
  return false if @deleted.nil?
  true
end