Class: ParamsConverter
- Inherits:
-
Object
- Object
- ParamsConverter
- Defined in:
- lib/ynap/values/params_converter.rb
Constant Summary collapse
- IMPORT_ID_PREFIX =
"GW"
- IMPORT_ID_FIXED_SIZE =
IMPORT_ID_PREFIX.length + 10 + 3
- MAX_IMPORT_ID_SIZE =
36
Instance Attribute Summary collapse
-
#account ⇒ Object
readonly
Returns the value of attribute account.
-
#plaid_transaction ⇒ Object
readonly
Returns the value of attribute plaid_transaction.
Instance Method Summary collapse
- #amount ⇒ Object
- #date ⇒ Object
- #import_id ⇒ Object
-
#initialize(account, plaid_transaction) ⇒ ParamsConverter
constructor
A new instance of ParamsConverter.
- #payee_name ⇒ Object
- #sliced_transaction_id ⇒ Object
- #to_params ⇒ Object
- #transaction_id ⇒ Object
- #transaction_id_length ⇒ Object
Constructor Details
#initialize(account, plaid_transaction) ⇒ ParamsConverter
Returns a new instance of ParamsConverter.
8 9 10 11 |
# File 'lib/ynap/values/params_converter.rb', line 8 def initialize(account, plaid_transaction) @account = account @plaid_transaction = plaid_transaction end |
Instance Attribute Details
#account ⇒ Object (readonly)
Returns the value of attribute account.
6 7 8 |
# File 'lib/ynap/values/params_converter.rb', line 6 def account @account end |
#plaid_transaction ⇒ Object (readonly)
Returns the value of attribute plaid_transaction.
6 7 8 |
# File 'lib/ynap/values/params_converter.rb', line 6 def plaid_transaction @plaid_transaction end |
Instance Method Details
#amount ⇒ Object
13 14 15 |
# File 'lib/ynap/values/params_converter.rb', line 13 def amount @amount ||= -(BigDecimal(plaid_transaction.amount.to_s) * 100).to_i end |
#date ⇒ Object
17 18 19 |
# File 'lib/ynap/values/params_converter.rb', line 17 def date @date ||= Date.parse(plaid_transaction.date) end |
#import_id ⇒ Object
33 34 35 |
# File 'lib/ynap/values/params_converter.rb', line 33 def import_id [IMPORT_ID_PREFIX, amount, date, sliced_transaction_id].join(":") end |
#payee_name ⇒ Object
37 38 39 |
# File 'lib/ynap/values/params_converter.rb', line 37 def payee_name @payee_name ||= plaid_transaction.merchant_name || PayeeParser.new.cleaned_name(plaid_transaction.name)[0, 50] end |
#sliced_transaction_id ⇒ Object
29 30 31 |
# File 'lib/ynap/values/params_converter.rb', line 29 def sliced_transaction_id @sliced_transaction_id ||= transaction_id[0, transaction_id_length] end |
#to_params ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/ynap/values/params_converter.rb', line 41 def to_params { account_id: account.ynab_id, amount: amount * 10, cleared: 'cleared', date: date, import_id: import_id, memo: plaid_transaction.name, payee_name: payee_name } end |
#transaction_id ⇒ Object
21 22 23 |
# File 'lib/ynap/values/params_converter.rb', line 21 def transaction_id @transaction_id ||= plaid_transaction.pending_transaction_id || plaid_transaction.transaction_id end |
#transaction_id_length ⇒ Object
25 26 27 |
# File 'lib/ynap/values/params_converter.rb', line 25 def transaction_id_length @transaction_id_length ||= MAX_IMPORT_ID_SIZE - IMPORT_ID_FIXED_SIZE - amount.to_s.size end |