Class: Account
- Inherits:
-
BridgeRecord
- Object
- BridgeRecord
- Account
- Defined in:
- lib/ynap/models/account.rb
Constant Summary collapse
- TRANSACTIONS_HORIZON =
30
Instance Attribute Summary collapse
-
#plaid_id ⇒ Object
readonly
Returns the value of attribute plaid_id.
-
#start_date ⇒ Object
readonly
Returns the value of attribute start_date.
-
#ynab_id ⇒ Object
readonly
Returns the value of attribute ynab_id.
Attributes inherited from BridgeRecord
#plaid_access_token, #plaid_client, #ynab_client
Instance Method Summary collapse
- #balances ⇒ Object
- #description ⇒ Object
-
#initialize(plaid_id:, plaid_access_token:, ynab_id: nil, start_date: nil) ⇒ Account
constructor
A new instance of Account.
- #plaid_account ⇒ Object
-
#plaid_accounts ⇒ Object
Plaid.
- #plaid_balance ⇒ Object
- #plaid_transactions ⇒ Object
- #reconciled? ⇒ Boolean
-
#ynab_account ⇒ Object
YNAB.
- #ynab_balance ⇒ Object
- #ynab_transactions ⇒ Object
Constructor Details
#initialize(plaid_id:, plaid_access_token:, ynab_id: nil, start_date: nil) ⇒ Account
Returns a new instance of Account.
9 10 11 12 13 14 15 16 |
# File 'lib/ynap/models/account.rb', line 9 def initialize(plaid_id:, plaid_access_token:, ynab_id: nil, start_date: nil) super(plaid_access_token) @plaid_id = plaid_id @ynab_id = ynab_id @start_date = Date.parse(start_date) unless start_date.nil? @to_date = Date.today @from_date = @start_date || (@to_date - TRANSACTIONS_HORIZON) end |
Instance Attribute Details
#plaid_id ⇒ Object (readonly)
Returns the value of attribute plaid_id.
7 8 9 |
# File 'lib/ynap/models/account.rb', line 7 def plaid_id @plaid_id end |
#start_date ⇒ Object (readonly)
Returns the value of attribute start_date.
7 8 9 |
# File 'lib/ynap/models/account.rb', line 7 def start_date @start_date end |
#ynab_id ⇒ Object (readonly)
Returns the value of attribute ynab_id.
7 8 9 |
# File 'lib/ynap/models/account.rb', line 7 def ynab_id @ynab_id end |
Instance Method Details
#balances ⇒ Object
23 24 25 |
# File 'lib/ynap/models/account.rb', line 23 def balances { plaid: plaid_balance, ynab: ynab_balance.to_plaid } end |
#description ⇒ Object
18 19 20 21 |
# File 'lib/ynap/models/account.rb', line 18 def description reconciled = reconciled? ? "✅" : "❌" "#{ynab_account.name}: #{plaid_balance} P#{reconciled}Y #{ynab_balance.to_plaid} #{plaid_account.balances.iso_currency_code}" end |
#plaid_account ⇒ Object
37 38 39 |
# File 'lib/ynap/models/account.rb', line 37 def plaid_account @plaid_account ||= plaid_accounts.find { |account| account.account_id == plaid_id } end |
#plaid_accounts ⇒ Object
Plaid
33 34 35 |
# File 'lib/ynap/models/account.rb', line 33 def plaid_accounts @plaid_accounts ||= plaid_client.accounts.balance.get(plaid_access_token).accounts end |
#plaid_balance ⇒ Object
41 42 43 |
# File 'lib/ynap/models/account.rb', line 41 def plaid_balance @plaid_balance ||= plaid_account.balances.available end |
#plaid_transactions ⇒ Object
45 46 47 |
# File 'lib/ynap/models/account.rb', line 45 def plaid_transactions @plaid_transactions ||= plaid_client.transactions.get(plaid_access_token, @from_date, @to_date, account_ids: [plaid_id]).transactions end |
#reconciled? ⇒ Boolean
27 28 29 |
# File 'lib/ynap/models/account.rb', line 27 def reconciled? plaid_balance.to_ynab == ynab_balance end |
#ynab_account ⇒ Object
YNAB
51 52 53 |
# File 'lib/ynap/models/account.rb', line 51 def ynab_account @ynab_account ||= ynab_client.accounts.get_account_by_id(Ynap.config.dig(:ynab, :budget_id), ynab_id).data.account end |
#ynab_balance ⇒ Object
55 56 57 |
# File 'lib/ynap/models/account.rb', line 55 def ynab_balance @ynab_balance ||= ynab_account.balance end |