Class: Ynaby::Transaction
Instance Attribute Summary collapse
-
#account ⇒ Object
readonly
Returns the value of attribute account.
-
#account_name ⇒ Object
readonly
Returns the value of attribute account_name.
-
#amount ⇒ Object
Returns the value of attribute amount.
-
#approved ⇒ Object
readonly
Returns the value of attribute approved.
-
#category_id ⇒ Object
readonly
Returns the value of attribute category_id.
-
#category_name ⇒ Object
readonly
Returns the value of attribute category_name.
-
#cleared ⇒ Object
readonly
Returns the value of attribute cleared.
-
#date ⇒ Object
readonly
Returns the value of attribute date.
-
#flag_color ⇒ Object
readonly
Returns the value of attribute flag_color.
-
#id ⇒ Object
Returns the value of attribute id.
-
#import_id ⇒ Object
readonly
Returns the value of attribute import_id.
-
#memo ⇒ Object
Returns the value of attribute memo.
-
#payee_id ⇒ Object
readonly
Returns the value of attribute payee_id.
-
#payee_name ⇒ Object
readonly
Returns the value of attribute payee_name.
-
#subtransactions ⇒ Object
readonly
Returns the value of attribute subtransactions.
-
#transfer_account_id ⇒ Object
readonly
Returns the value of attribute transfer_account_id.
-
#transfer_transaction_id ⇒ Object
readonly
Returns the value of attribute transfer_transaction_id.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(id: nil, date:, amount:, memo: nil, cleared: nil, approved: nil, flag_color: nil, payee_id: nil, category_id: nil, transfer_account_id: nil, transfer_transaction_id: nil, import_id: nil, account_name: nil, payee_name:, category_name: nil, account:, subtransactions: nil) ⇒ Transaction
constructor
A new instance of Transaction.
- #update ⇒ Object
- #upload ⇒ Object
- #upload_hash ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(id: nil, date:, amount:, memo: nil, cleared: nil, approved: nil, flag_color: nil, payee_id: nil, category_id: nil, transfer_account_id: nil, transfer_transaction_id: nil, import_id: nil, account_name: nil, payee_name:, category_name: nil, account:, subtransactions: nil) ⇒ Transaction
Returns a new instance of Transaction.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/ynaby/transaction.rb', line 10 def initialize(id: nil, date:, amount:, memo: nil, cleared: nil, approved: nil, flag_color: nil, payee_id: nil, category_id: nil, transfer_account_id: nil, transfer_transaction_id: nil, import_id: nil, account_name: nil, payee_name:, category_name: nil, account:, subtransactions: nil) @id = id @date = date @amount = amount @memo = memo @cleared = cleared @approved = approved @flag_color = flag_color @payee_id = payee_id @category_id = category_id @transfer_account_id = transfer_account_id @transfer_transaction_id = transfer_transaction_id @import_id = import_id @account_name = account_name @payee_name = payee_name @category_name = category_name @account = account @subtransactions = subtransactions end |
Instance Attribute Details
#account ⇒ Object (readonly)
Returns the value of attribute account.
3 4 5 |
# File 'lib/ynaby/transaction.rb', line 3 def account @account end |
#account_name ⇒ Object (readonly)
Returns the value of attribute account_name.
3 4 5 |
# File 'lib/ynaby/transaction.rb', line 3 def account_name @account_name end |
#amount ⇒ Object
Returns the value of attribute amount.
8 9 10 |
# File 'lib/ynaby/transaction.rb', line 8 def amount @amount end |
#approved ⇒ Object (readonly)
Returns the value of attribute approved.
3 4 5 |
# File 'lib/ynaby/transaction.rb', line 3 def approved @approved end |
#category_id ⇒ Object (readonly)
Returns the value of attribute category_id.
3 4 5 |
# File 'lib/ynaby/transaction.rb', line 3 def category_id @category_id end |
#category_name ⇒ Object (readonly)
Returns the value of attribute category_name.
3 4 5 |
# File 'lib/ynaby/transaction.rb', line 3 def category_name @category_name end |
#cleared ⇒ Object (readonly)
Returns the value of attribute cleared.
3 4 5 |
# File 'lib/ynaby/transaction.rb', line 3 def cleared @cleared end |
#date ⇒ Object (readonly)
Returns the value of attribute date.
3 4 5 |
# File 'lib/ynaby/transaction.rb', line 3 def date @date end |
#flag_color ⇒ Object (readonly)
Returns the value of attribute flag_color.
3 4 5 |
# File 'lib/ynaby/transaction.rb', line 3 def flag_color @flag_color end |
#id ⇒ Object
Returns the value of attribute id.
8 9 10 |
# File 'lib/ynaby/transaction.rb', line 8 def id @id end |
#import_id ⇒ Object (readonly)
Returns the value of attribute import_id.
3 4 5 |
# File 'lib/ynaby/transaction.rb', line 3 def import_id @import_id end |
#memo ⇒ Object
Returns the value of attribute memo.
8 9 10 |
# File 'lib/ynaby/transaction.rb', line 8 def memo @memo end |
#payee_id ⇒ Object (readonly)
Returns the value of attribute payee_id.
3 4 5 |
# File 'lib/ynaby/transaction.rb', line 3 def payee_id @payee_id end |
#payee_name ⇒ Object (readonly)
Returns the value of attribute payee_name.
3 4 5 |
# File 'lib/ynaby/transaction.rb', line 3 def payee_name @payee_name end |
#subtransactions ⇒ Object (readonly)
Returns the value of attribute subtransactions.
3 4 5 |
# File 'lib/ynaby/transaction.rb', line 3 def subtransactions @subtransactions end |
#transfer_account_id ⇒ Object (readonly)
Returns the value of attribute transfer_account_id.
3 4 5 |
# File 'lib/ynaby/transaction.rb', line 3 def transfer_account_id @transfer_account_id end |
#transfer_transaction_id ⇒ Object (readonly)
Returns the value of attribute transfer_transaction_id.
3 4 5 |
# File 'lib/ynaby/transaction.rb', line 3 def transfer_transaction_id @transfer_transaction_id end |
Class Method Details
.parse(object:, account:) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/ynaby/transaction.rb', line 87 def self.parse(object:, account:) new( id: object.id, date: object.date, amount: object.amount.to_i, memo: object.memo, cleared: object.cleared, approved: object.approved, flag_color: object.flag_color, payee_id: object.payee_id, category_id: object.category_id, transfer_account_id: object.transfer_account_id, transfer_transaction_id: object.transfer_transaction_id, import_id: object.import_id, account_name: object.account_name, payee_name: object.payee_name, category_name: object.category_name, account: account, subtransactions: object.subtransactions.map(&:to_body) ) end |
Instance Method Details
#update ⇒ Object
77 78 79 80 81 82 83 84 85 |
# File 'lib/ynaby/transaction.rb', line 77 def update body = { transaction: upload_hash } response = ynab_client.transactions.update_transaction(budget_id, id, body) self.class.parse(object: response.data.transaction, account: account) end |
#upload ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/ynaby/transaction.rb', line 47 def upload body = { transaction: upload_hash } response = ynab_client.transactions.create_transaction(budget_id, body) self.class.parse(object: response.data.transaction, account: account) end |
#upload_hash ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/ynaby/transaction.rb', line 57 def upload_hash hash = { account_id: @account.id, date: @date.to_date.iso8601, amount: @amount, import_id: @import_id, memo: @memo&.slice(0...50) } if @transfer_account_id && @transfer_transaction_id hash[:transfer_account_id] = @transfer_account_id hash[:transfer_transaction_id] = @transfer_transaction_id else hash[:payee_name] = @payee_name hash[:payee_id] = nil end hash end |