Class: YNAB::Category

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

Defined Under Namespace

Classes: EnumAttributeValidator

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Category

Initializes the object



192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
# File 'lib/ynab/models/category.rb', line 192

def initialize(attributes = {})
  if (!attributes.is_a?(Hash))
    fail ArgumentError, "The input argument (attributes) must be a hash in `YNAB::Category` initialize method"
  end

  # check to see if the attribute exists and convert string to symbol for hash key
  attributes = attributes.each_with_object({}) { |(k, v), h|
    if (!self.class.attribute_map.key?(k.to_sym))
      fail ArgumentError, "`#{k}` is not a valid attribute in `YNAB::Category`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
    end
    h[k.to_sym] = v
  }

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

  if attributes.key?(:'category_group_id')
    self.category_group_id = attributes[:'category_group_id']
  end

  if attributes.key?(:'category_group_name')
    self.category_group_name = attributes[:'category_group_name']
  end

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

  if attributes.key?(:'hidden')
    self.hidden = attributes[:'hidden']
  end

  if attributes.key?(:'original_category_group_id')
    self.original_category_group_id = attributes[:'original_category_group_id']
  end

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

  if attributes.key?(:'budgeted')
    self.budgeted = attributes[:'budgeted']
  end

  if attributes.key?(:'activity')
    self.activity = attributes[:'activity']
  end

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

  if attributes.key?(:'goal_type')
    self.goal_type = attributes[:'goal_type']
  end

  if attributes.key?(:'goal_needs_whole_amount')
    self.goal_needs_whole_amount = attributes[:'goal_needs_whole_amount']
  end

  if attributes.key?(:'goal_day')
    self.goal_day = attributes[:'goal_day']
  end

  if attributes.key?(:'goal_cadence')
    self.goal_cadence = attributes[:'goal_cadence']
  end

  if attributes.key?(:'goal_cadence_frequency')
    self.goal_cadence_frequency = attributes[:'goal_cadence_frequency']
  end

  if attributes.key?(:'goal_creation_month')
    self.goal_creation_month = attributes[:'goal_creation_month']
  end

  if attributes.key?(:'goal_target')
    self.goal_target = attributes[:'goal_target']
  end

  if attributes.key?(:'goal_target_month')
    self.goal_target_month = attributes[:'goal_target_month']
  end

  if attributes.key?(:'goal_percentage_complete')
    self.goal_percentage_complete = attributes[:'goal_percentage_complete']
  end

  if attributes.key?(:'goal_months_to_budget')
    self.goal_months_to_budget = attributes[:'goal_months_to_budget']
  end

  if attributes.key?(:'goal_under_funded')
    self.goal_under_funded = attributes[:'goal_under_funded']
  end

  if attributes.key?(:'goal_overall_funded')
    self.goal_overall_funded = attributes[:'goal_overall_funded']
  end

  if attributes.key?(:'goal_overall_left')
    self.goal_overall_left = attributes[:'goal_overall_left']
  end

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

Instance Attribute Details

#activityObject

Activity amount in milliunits format



35
36
37
# File 'lib/ynab/models/category.rb', line 35

def activity
  @activity
end

#balanceObject

Balance in milliunits format



38
39
40
# File 'lib/ynab/models/category.rb', line 38

def balance
  @balance
end

#budgetedObject

Budgeted amount in milliunits format



32
33
34
# File 'lib/ynab/models/category.rb', line 32

def budgeted
  @budgeted
end

#category_group_idObject

Returns the value of attribute category_group_id.



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

def category_group_id
  @category_group_id
end

#category_group_nameObject

Returns the value of attribute category_group_name.



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

def category_group_name
  @category_group_name
end

#deletedObject

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



80
81
82
# File 'lib/ynab/models/category.rb', line 80

def deleted
  @deleted
end

#goal_cadenceObject

The goal cadence. Value in range 0-14. There are two subsets of these values which behave differently. For values 0, 1, 2, and 13, the goal’s due date repeats every goal_cadence * goal_cadence_frequency, where 0 = None, 1 = Monthly, 2 = Weekly, and 13 = Yearly. For example, goal_cadence 1 with goal_cadence_frequency 2 means the goal is due every other month. For values 3-12 and 14, goal_cadence_frequency is ignored and the goal’s due date repeats every goal_cadence, where 3 = Every 2 Months, 4 = Every 3 Months, …, 12 = Every 11 Months, and 14 = Every 2 Years.



50
51
52
# File 'lib/ynab/models/category.rb', line 50

def goal_cadence
  @goal_cadence
end

#goal_cadence_frequencyObject

The goal cadence frequency. When goal_cadence is 0, 1, 2, or 13, a goal’s due date repeats every goal_cadence * goal_cadence_frequency. For example, goal_cadence 1 with goal_cadence_frequency 2 means the goal is due every other month. When goal_cadence is 3-12 or 14, goal_cadence_frequency is ignored.



53
54
55
# File 'lib/ynab/models/category.rb', line 53

def goal_cadence_frequency
  @goal_cadence_frequency
end

#goal_creation_monthObject

The month a goal was created



56
57
58
# File 'lib/ynab/models/category.rb', line 56

def goal_creation_month
  @goal_creation_month
end

#goal_dayObject

A day offset modifier for the goal’s due date. When goal_cadence is 2 (Weekly), this value specifies which day of the week the goal is due (0 = Sunday, 6 = Saturday). Otherwise, this value specifies which day of the month the goal is due (1 = 1st, 31 = 31st, null = Last day of Month).



47
48
49
# File 'lib/ynab/models/category.rb', line 47

def goal_day
  @goal_day
end

#goal_months_to_budgetObject

The number of months, including the current month, left in the current goal period.



68
69
70
# File 'lib/ynab/models/category.rb', line 68

def goal_months_to_budget
  @goal_months_to_budget
end

#goal_needs_whole_amountObject

Indicates the monthly rollover behavior for "NEED"-type goals. When "true", the goal will always ask for the target amount in the new month ("Set Aside"). When "false", previous month category funding is used ("Refill"). For other goal types, this field will be null.



44
45
46
# File 'lib/ynab/models/category.rb', line 44

def goal_needs_whole_amount
  @goal_needs_whole_amount
end

#goal_overall_fundedObject

The total amount funded towards the goal within the current goal period.



74
75
76
# File 'lib/ynab/models/category.rb', line 74

def goal_overall_funded
  @goal_overall_funded
end

#goal_overall_leftObject

The amount of funding still needed to complete the goal within the current goal period.



77
78
79
# File 'lib/ynab/models/category.rb', line 77

def goal_overall_left
  @goal_overall_left
end

#goal_percentage_completeObject

The percentage completion of the goal



65
66
67
# File 'lib/ynab/models/category.rb', line 65

def goal_percentage_complete
  @goal_percentage_complete
end

#goal_targetObject

The goal target amount in milliunits



59
60
61
# File 'lib/ynab/models/category.rb', line 59

def goal_target
  @goal_target
end

#goal_target_monthObject

The original target month for the goal to be completed. Only some goal types specify this date.



62
63
64
# File 'lib/ynab/models/category.rb', line 62

def goal_target_month
  @goal_target_month
end

#goal_typeObject

The type of goal, if the category has a goal (TB=‘Target Category Balance’, TBD=‘Target Category Balance by Date’, MF=‘Monthly Funding’, NEED=‘Plan Your Spending’)



41
42
43
# File 'lib/ynab/models/category.rb', line 41

def goal_type
  @goal_type
end

#goal_under_fundedObject

The amount of funding still needed in the current month to stay on track towards completing the goal within the current goal period. This amount will generally correspond to the ‘Underfunded’ amount in the web and mobile clients except when viewing a category with a Needed for Spending Goal in a future month. The web and mobile clients will ignore any funding from a prior goal period when viewing category with a Needed for Spending Goal in a future month.



71
72
73
# File 'lib/ynab/models/category.rb', line 71

def goal_under_funded
  @goal_under_funded
end

#hiddenObject

Whether or not the category is hidden



24
25
26
# File 'lib/ynab/models/category.rb', line 24

def hidden
  @hidden
end

#idObject

Returns the value of attribute id.



15
16
17
# File 'lib/ynab/models/category.rb', line 15

def id
  @id
end

#nameObject

Returns the value of attribute name.



21
22
23
# File 'lib/ynab/models/category.rb', line 21

def name
  @name
end

#noteObject

Returns the value of attribute note.



29
30
31
# File 'lib/ynab/models/category.rb', line 29

def note
  @note
end

#original_category_group_idObject

DEPRECATED: No longer used. Value will always be null.



27
28
29
# File 'lib/ynab/models/category.rb', line 27

def original_category_group_id
  @original_category_group_id
end

Class Method Details

._deserialize(type, value) ⇒ Object

Deserializes the data based on type



401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
# File 'lib/ynab/models/category.rb', line 401

def self._deserialize(type, value)
  case type.to_sym
  when :Time
    Time.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
    # models (e.g. Pet) or oneOf
    klass = YNAB.const_get(type)
    klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
  end
end

.acceptable_attributesObject

Returns all the JSON keys this model knows about



135
136
137
# File 'lib/ynab/models/category.rb', line 135

def self.acceptable_attributes
  attribute_map.values
end

.attribute_mapObject

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



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

def self.attribute_map
  {
    :'id' => :'id',
    :'category_group_id' => :'category_group_id',
    :'category_group_name' => :'category_group_name',
    :'name' => :'name',
    :'hidden' => :'hidden',
    :'original_category_group_id' => :'original_category_group_id',
    :'note' => :'note',
    :'budgeted' => :'budgeted',
    :'activity' => :'activity',
    :'balance' => :'balance',
    :'goal_type' => :'goal_type',
    :'goal_needs_whole_amount' => :'goal_needs_whole_amount',
    :'goal_day' => :'goal_day',
    :'goal_cadence' => :'goal_cadence',
    :'goal_cadence_frequency' => :'goal_cadence_frequency',
    :'goal_creation_month' => :'goal_creation_month',
    :'goal_target' => :'goal_target',
    :'goal_target_month' => :'goal_target_month',
    :'goal_percentage_complete' => :'goal_percentage_complete',
    :'goal_months_to_budget' => :'goal_months_to_budget',
    :'goal_under_funded' => :'goal_under_funded',
    :'goal_overall_funded' => :'goal_overall_funded',
    :'goal_overall_left' => :'goal_overall_left',
    :'deleted' => :'deleted'
  }
end

.build_from_hash(attributes) ⇒ Object

Builds the object from hash



377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
# File 'lib/ynab/models/category.rb', line 377

def self.build_from_hash(attributes)
  return nil unless attributes.is_a?(Hash)
  attributes = attributes.transform_keys(&:to_sym)
  transformed_hash = {}
  openapi_types.each_pair do |key, type|
    if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
      transformed_hash["#{key}"] = nil
    elsif type =~ /\AArray<(.*)>/i
      # check to ensure the input is an array given that the attribute
      # is documented as an array but the input is not
      if attributes[attribute_map[key]].is_a?(Array)
        transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
      end
    elsif !attributes[attribute_map[key]].nil?
      transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
    end
  end
  new(transformed_hash)
end

.openapi_nullableObject

List of attributes with nullable: true



170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/ynab/models/category.rb', line 170

def self.openapi_nullable
  Set.new([
    :'original_category_group_id',
    :'note',
    :'goal_type',
    :'goal_needs_whole_amount',
    :'goal_day',
    :'goal_cadence',
    :'goal_cadence_frequency',
    :'goal_creation_month',
    :'goal_target',
    :'goal_target_month',
    :'goal_percentage_complete',
    :'goal_months_to_budget',
    :'goal_under_funded',
    :'goal_overall_funded',
    :'goal_overall_left',
  ])
end

.openapi_typesObject

Attribute type mapping.



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/ynab/models/category.rb', line 140

def self.openapi_types
  {
    :'id' => :'String',
    :'category_group_id' => :'String',
    :'category_group_name' => :'String',
    :'name' => :'String',
    :'hidden' => :'Boolean',
    :'original_category_group_id' => :'String',
    :'note' => :'String',
    :'budgeted' => :'Integer',
    :'activity' => :'Integer',
    :'balance' => :'Integer',
    :'goal_type' => :'String',
    :'goal_needs_whole_amount' => :'Boolean',
    :'goal_day' => :'Integer',
    :'goal_cadence' => :'Integer',
    :'goal_cadence_frequency' => :'Integer',
    :'goal_creation_month' => :'Date',
    :'goal_target' => :'Integer',
    :'goal_target_month' => :'Date',
    :'goal_percentage_complete' => :'Integer',
    :'goal_months_to_budget' => :'Integer',
    :'goal_under_funded' => :'Integer',
    :'goal_overall_funded' => :'Integer',
    :'goal_overall_left' => :'Integer',
    :'deleted' => :'Boolean'
  }
end

Instance Method Details

#==(o) ⇒ Object

Checks equality by comparing each attribute.



333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
# File 'lib/ynab/models/category.rb', line 333

def ==(o)
  return true if self.equal?(o)
  self.class == o.class &&
      id == o.id &&
      category_group_id == o.category_group_id &&
      category_group_name == o.category_group_name &&
      name == o.name &&
      hidden == o.hidden &&
      original_category_group_id == o.original_category_group_id &&
      note == o.note &&
      budgeted == o.budgeted &&
      activity == o.activity &&
      balance == o.balance &&
      goal_type == o.goal_type &&
      goal_needs_whole_amount == o.goal_needs_whole_amount &&
      goal_day == o.goal_day &&
      goal_cadence == o.goal_cadence &&
      goal_cadence_frequency == o.goal_cadence_frequency &&
      goal_creation_month == o.goal_creation_month &&
      goal_target == o.goal_target &&
      goal_target_month == o.goal_target_month &&
      goal_percentage_complete == o.goal_percentage_complete &&
      goal_months_to_budget == o.goal_months_to_budget &&
      goal_under_funded == o.goal_under_funded &&
      goal_overall_funded == o.goal_overall_funded &&
      goal_overall_left == o.goal_overall_left &&
      deleted == o.deleted
end

#_to_hash(value) ⇒ Hash

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



472
473
474
475
476
477
478
479
480
481
482
483
484
# File 'lib/ynab/models/category.rb', line 472

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

#eql?(o) ⇒ Boolean

See Also:

  • `==` method


364
365
366
# File 'lib/ynab/models/category.rb', line 364

def eql?(o)
  self == o
end

#hashInteger

Calculates hash code according to all attributes.



370
371
372
# File 'lib/ynab/models/category.rb', line 370

def hash
  [id, category_group_id, category_group_name, name, hidden, original_category_group_id, note, budgeted, activity, balance, goal_type, goal_needs_whole_amount, goal_day, goal_cadence, goal_cadence_frequency, goal_creation_month, goal_target, goal_target_month, goal_percentage_complete, goal_months_to_budget, goal_under_funded, goal_overall_funded, goal_overall_left, deleted].hash
end

#list_invalid_propertiesObject

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



304
305
306
307
# File 'lib/ynab/models/category.rb', line 304

def list_invalid_properties
  invalid_properties = Array.new
  invalid_properties
end

#to_bodyHash

to_body is an alias to to_hash (backward compatibility)



448
449
450
# File 'lib/ynab/models/category.rb', line 448

def to_body
  to_hash
end

#to_hashHash

Returns the object in the form of hash



454
455
456
457
458
459
460
461
462
463
464
465
466
# File 'lib/ynab/models/category.rb', line 454

def to_hash
  hash = {}
  self.class.attribute_map.each_pair do |attr, param|
    value = self.send(attr)
    if value.nil?
      is_nullable = self.class.openapi_nullable.include?(attr)
      next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
    end

    hash[param] = _to_hash(value)
  end
  hash
end

#to_sString

Returns the string representation of the object



442
443
444
# File 'lib/ynab/models/category.rb', line 442

def to_s
  to_hash.to_s
end

#valid?Boolean

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



311
312
313
314
315
316
317
318
319
320
321
322
323
# File 'lib/ynab/models/category.rb', line 311

def valid?
  return false if @id.nil?
  return false if @category_group_id.nil?
  return false if @name.nil?
  return false if @hidden.nil?
  return false if @budgeted.nil?
  return false if @activity.nil?
  return false if @balance.nil?
  goal_type_validator = EnumAttributeValidator.new('String', ["TB", "TBD", "MF", "NEED", "DEBT"])
  return false unless goal_type_validator.valid?(@goal_type)
  return false if @deleted.nil?
  true
end