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

Parameters:

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

    Model attributes in the form of hash



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

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?(:'category_group_id')
    self.category_group_id = attributes[:'category_group_id']
  end

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

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

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

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

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

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

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

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

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

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

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

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

  if attributes.has_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.



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

def category_group_id
  @category_group_id
end

#deletedObject

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



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

def deleted
  @deleted
end

#goal_creation_monthObject

The month a goal was created



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

def goal_creation_month
  @goal_creation_month
end

#goal_percentage_completeObject

The percentage completion of the goal



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

def goal_percentage_complete
  @goal_percentage_complete
end

#goal_targetObject

The goal target amount in milliunits



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

def goal_target
  @goal_target
end

#goal_target_monthObject

If the goal type is ‘TBD’ (Target Category Balance by Date), this is the target month for the goal to be completed



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

def goal_target_month
  @goal_target_month
end

#goal_typeObject

The type of goal, if the cagegory has a goal (TB=Target Category Balance, TBD=Target Category Balance by Date, MF=Monthly Funding)



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

def goal_type
  @goal_type
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.



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

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

If category is hidden this is the id of the category group it originally belonged to before it was hidden.



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

def original_category_group_id
  @original_category_group_id
end

Class Method Details

.attribute_mapObject

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



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/ynab/models/category.rb', line 81

def self.attribute_map
  {
    :'id' => :'id',
    :'category_group_id' => :'category_group_id',
    :'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_creation_month' => :'goal_creation_month',
    :'goal_target' => :'goal_target',
    :'goal_target_month' => :'goal_target_month',
    :'goal_percentage_complete' => :'goal_percentage_complete',
    :'deleted' => :'deleted'
  }
end

.swagger_typesObject

Attribute type mapping.



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/ynab/models/category.rb', line 102

def self.swagger_types
  {
    :'id' => :'String',
    :'category_group_id' => :'String',
    :'name' => :'String',
    :'hidden' => :'BOOLEAN',
    :'original_category_group_id' => :'String',
    :'note' => :'String',
    :'budgeted' => :'Integer',
    :'activity' => :'Integer',
    :'balance' => :'Integer',
    :'goal_type' => :'String',
    :'goal_creation_month' => :'Date',
    :'goal_target' => :'Integer',
    :'goal_target_month' => :'Date',
    :'goal_percentage_complete' => :'Integer',
    :'deleted' => :'BOOLEAN'
  }
end

Instance Method Details

#==(o) ⇒ Object

Checks equality by comparing each attribute.

Parameters:

  • Object (Object)

    to be compared



288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
# File 'lib/ynab/models/category.rb', line 288

def ==(o)
  return true if self.equal?(o)
  self.class == o.class &&
      id == o.id &&
      category_group_id == o.category_group_id &&
      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_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 &&
      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



344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
# File 'lib/ynab/models/category.rb', line 344

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



410
411
412
413
414
415
416
417
418
419
420
421
422
# File 'lib/ynab/models/category.rb', line 410

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



323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
# File 'lib/ynab/models/category.rb', line 323

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


310
311
312
# File 'lib/ynab/models/category.rb', line 310

def eql?(o)
  self == o
end

#hashFixnum

Calculates hash code according to all attributes.

Returns:

  • (Fixnum)

    Hash code



316
317
318
# File 'lib/ynab/models/category.rb', line 316

def hash
  [id, category_group_id, name, hidden, original_category_group_id, note, budgeted, activity, balance, goal_type, goal_creation_month, goal_target, goal_target_month, goal_percentage_complete, 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



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

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

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

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

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

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

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

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

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

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

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

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

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

  if @goal_percentage_complete.nil?
    invalid_properties.push('invalid value for "goal_percentage_complete", goal_percentage_complete 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



390
391
392
# File 'lib/ynab/models/category.rb', line 390

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



396
397
398
399
400
401
402
403
404
# File 'lib/ynab/models/category.rb', line 396

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



384
385
386
# File 'lib/ynab/models/category.rb', line 384

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



256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
# File 'lib/ynab/models/category.rb', line 256

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 @note.nil?
  return false if @budgeted.nil?
  return false if @activity.nil?
  return false if @balance.nil?
  return false if @goal_type.nil?
  goal_type_validator = EnumAttributeValidator.new('String', ['TB', 'TBD', 'MF'])
  return false unless goal_type_validator.valid?(@goal_type)
  return false if @goal_creation_month.nil?
  return false if @goal_target.nil?
  return false if @goal_target_month.nil?
  return false if @goal_percentage_complete.nil?
  return false if @deleted.nil?
  true
end