Class: Transformers::Cleaners::UBSCredit

Inherits:
Cleaner
  • Object
show all
Defined in:
lib/ynab_convert/transformers/cleaners/ubs_credit_cleaner.rb

Overview

UBS Switzerland Credit Card accounts cleaner

Constant Summary collapse

HEADERS =
{
  date: 3,
  payee: 4,
  outflow: 10,
  inflow: 11
}.freeze

Instance Method Summary collapse

Instance Method Details

#parse_amount(amount) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/ynab_convert/transformers/cleaners/ubs_credit_cleaner.rb', line 36

def parse_amount(amount)
  unless amount.nil? || amount.is_a?(Numeric)
    return amount.delete("'").to_f
  end

  amount
end

#parse_transaction_date(date) ⇒ Object



27
28
29
30
31
32
33
34
# File 'lib/ynab_convert/transformers/cleaners/ubs_credit_cleaner.rb', line 27

def parse_transaction_date(date)
  # Transaction dates are dd.mm.YYYY which Date#parse understands, but
  # the CSV::Converter[:date] doesn't recognize it as it's not looking
  # for dot separators.
  return Date.parse(date) unless date.is_a?(Date) || date.nil?

  date
end

#run(row) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/ynab_convert/transformers/cleaners/ubs_credit_cleaner.rb', line 14

def run(row)
  date = parse_transaction_date(row[HEADERS[:date]])
  outflow = parse_amount(row[HEADERS[:outflow]])
  inflow = parse_amount(row[HEADERS[:inflow]])

  cleaned_row = row.dup
  cleaned_row[HEADERS[:date]] = date
  cleaned_row[HEADERS[:outflow]] = outflow
  cleaned_row[HEADERS[:inflow]] = inflow

  cleaned_row
end