Class: ThePlaidApi::CategoryExpenses

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/the_plaid_api/models/category_expenses.rb

Overview

Detailed expense information for a specific credit category, including transaction count and total amount spent.

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: SKIP, transactions_count: SKIP, amount: SKIP, iso_currency_code: SKIP, unofficial_currency_code: SKIP, monthly_average: SKIP, additional_properties: nil) ⇒ CategoryExpenses

Returns a new instance of CategoryExpenses.



83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/the_plaid_api/models/category_expenses.rb', line 83

def initialize(id: SKIP, transactions_count: SKIP, amount: SKIP,
               iso_currency_code: SKIP, unofficial_currency_code: SKIP,
               monthly_average: SKIP, additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @id = id unless id == SKIP
  @transactions_count = transactions_count unless transactions_count == SKIP
  @amount = amount unless amount == SKIP
  @iso_currency_code = iso_currency_code unless iso_currency_code == SKIP
  @unofficial_currency_code = unofficial_currency_code unless unofficial_currency_code == SKIP
  @monthly_average = monthly_average unless monthly_average == SKIP
  @additional_properties = additional_properties
end

Instance Attribute Details

#amountFloat

The total value for all the transactions that fall into this category within the given time window.

Returns:

  • (Float)


28
29
30
# File 'lib/the_plaid_api/models/category_expenses.rb', line 28

def amount
  @amount
end

#idString

The ID of the credit category. See the [category taxonomy](plaid.com/documents/credit-category-taxonomy.csv) for a full listing of category IDs.

Returns:

  • (String)


18
19
20
# File 'lib/the_plaid_api/models/category_expenses.rb', line 18

def id
  @id
end

#iso_currency_codeString

The ISO-4217 currency code of the amount. Always ‘null` if `unofficial_currency_code` is non-`null`.

Returns:

  • (String)


33
34
35
# File 'lib/the_plaid_api/models/category_expenses.rb', line 33

def iso_currency_code
  @iso_currency_code
end

#monthly_averageMonthlyAverage

The monthly average amount calculated by dividing the total by the number of calendar months in the time period.

Returns:



46
47
48
# File 'lib/the_plaid_api/models/category_expenses.rb', line 46

def monthly_average
  @monthly_average
end

#transactions_countInteger

The total number of transactions that fall into this credit category within the given time window.

Returns:

  • (Integer)


23
24
25
# File 'lib/the_plaid_api/models/category_expenses.rb', line 23

def transactions_count
  @transactions_count
end

#unofficial_currency_codeString

The unofficial currency code associated with the amount. Always ‘null` if `iso_currency_code` is non-`null`. See the [currency code schema](plaid.com/docs/api/accounts#currency-code-schema) for a full listing of supported `unofficial_currency_code`s.

Returns:

  • (String)


41
42
43
# File 'lib/the_plaid_api/models/category_expenses.rb', line 41

def unofficial_currency_code
  @unofficial_currency_code
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



99
100
101
102
103
104
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
# File 'lib/the_plaid_api/models/category_expenses.rb', line 99

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  id = hash.key?('id') ? hash['id'] : SKIP
  transactions_count =
    hash.key?('transactions_count') ? hash['transactions_count'] : SKIP
  amount = hash.key?('amount') ? hash['amount'] : SKIP
  iso_currency_code =
    hash.key?('iso_currency_code') ? hash['iso_currency_code'] : SKIP
  unofficial_currency_code =
    hash.key?('unofficial_currency_code') ? hash['unofficial_currency_code'] : SKIP
  monthly_average = MonthlyAverage.from_hash(hash['monthly_average']) if
    hash['monthly_average']

  # Create a new hash for additional properties, removing known properties.
  new_hash = hash.reject { |k, _| names.value?(k) }

  additional_properties = APIHelper.get_additional_properties(
    new_hash, proc { |value| value }
  )

  # Create object from extracted values.
  CategoryExpenses.new(id: id,
                       transactions_count: transactions_count,
                       amount: amount,
                       iso_currency_code: iso_currency_code,
                       unofficial_currency_code: unofficial_currency_code,
                       monthly_average: monthly_average,
                       additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



49
50
51
52
53
54
55
56
57
58
# File 'lib/the_plaid_api/models/category_expenses.rb', line 49

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['id'] = 'id'
  @_hash['transactions_count'] = 'transactions_count'
  @_hash['amount'] = 'amount'
  @_hash['iso_currency_code'] = 'iso_currency_code'
  @_hash['unofficial_currency_code'] = 'unofficial_currency_code'
  @_hash['monthly_average'] = 'monthly_average'
  @_hash
end

.nullablesObject

An array for nullable fields



73
74
75
76
77
78
79
80
81
# File 'lib/the_plaid_api/models/category_expenses.rb', line 73

def self.nullables
  %w[
    transactions_count
    amount
    iso_currency_code
    unofficial_currency_code
    monthly_average
  ]
end

.optionalsObject

An array for optional fields



61
62
63
64
65
66
67
68
69
70
# File 'lib/the_plaid_api/models/category_expenses.rb', line 61

def self.optionals
  %w[
    id
    transactions_count
    amount
    iso_currency_code
    unofficial_currency_code
    monthly_average
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



141
142
143
144
145
146
147
# File 'lib/the_plaid_api/models/category_expenses.rb', line 141

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} id: #{@id.inspect}, transactions_count: #{@transactions_count.inspect},"\
  " amount: #{@amount.inspect}, iso_currency_code: #{@iso_currency_code.inspect},"\
  " unofficial_currency_code: #{@unofficial_currency_code.inspect}, monthly_average:"\
  " #{@monthly_average.inspect}, additional_properties: #{@additional_properties}>"
end

#to_sObject

Provides a human-readable string representation of the object.



132
133
134
135
136
137
138
# File 'lib/the_plaid_api/models/category_expenses.rb', line 132

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} id: #{@id}, transactions_count: #{@transactions_count}, amount: #{@amount},"\
  " iso_currency_code: #{@iso_currency_code}, unofficial_currency_code:"\
  " #{@unofficial_currency_code}, monthly_average: #{@monthly_average}, additional_properties:"\
  " #{@additional_properties}>"
end