ynab_convert 1.0.8 → 2.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/publish.yml +36 -0
- data/.github/workflows/test.yml +31 -0
- data/.gitignore +2 -0
- data/.rubocop.yml +10 -2
- data/Gemfile.lock +39 -14
- data/Guardfile +1 -29
- data/README.md +82 -7
- data/lib/ynab_convert/api_clients/api_client.rb +24 -0
- data/lib/ynab_convert/api_clients/currency_api.rb +66 -0
- data/lib/ynab_convert/documents/statements/example_statement.rb +16 -0
- data/lib/ynab_convert/documents/statements/n26_statement.rb +24 -0
- data/lib/ynab_convert/documents/statements/statement.rb +39 -0
- data/lib/ynab_convert/documents/statements/ubs_chequing_statement.rb +20 -0
- data/lib/ynab_convert/documents/statements/ubs_credit_statement.rb +19 -0
- data/lib/ynab_convert/documents/statements/wise_statement.rb +17 -0
- data/lib/ynab_convert/documents/ynab4_files/ynab4_file.rb +58 -0
- data/lib/ynab_convert/documents.rb +17 -0
- data/lib/ynab_convert/logger.rb +1 -1
- data/lib/ynab_convert/processors/example_processor.rb +24 -0
- data/lib/ynab_convert/processors/n26_processor.rb +26 -0
- data/lib/ynab_convert/processors/processor.rb +75 -0
- data/lib/ynab_convert/processors/ubs_chequing_processor.rb +21 -0
- data/lib/ynab_convert/processors/ubs_credit_processor.rb +17 -0
- data/lib/ynab_convert/processors/wise_processor.rb +19 -0
- data/lib/ynab_convert/processors.rb +2 -2
- data/lib/ynab_convert/transformers/cleaners/cleaner.rb +17 -0
- data/lib/ynab_convert/transformers/cleaners/n26_cleaner.rb +13 -0
- data/lib/ynab_convert/transformers/cleaners/ubs_chequing_cleaner.rb +98 -0
- data/lib/ynab_convert/transformers/cleaners/ubs_credit_cleaner.rb +45 -0
- data/lib/ynab_convert/transformers/cleaners/wise_cleaner.rb +39 -0
- data/lib/ynab_convert/transformers/enhancers/enhancer.rb +20 -0
- data/lib/ynab_convert/transformers/enhancers/n26_enhancer.rb +74 -0
- data/lib/ynab_convert/transformers/enhancers/wise_enhancer.rb +87 -0
- data/lib/ynab_convert/transformers/formatters/example_formatter.rb +12 -0
- data/lib/ynab_convert/transformers/formatters/formatter.rb +91 -0
- data/lib/ynab_convert/transformers/formatters/n26_formatter.rb +19 -0
- data/lib/ynab_convert/transformers/formatters/ubs_chequing_formatter.rb +12 -0
- data/lib/ynab_convert/transformers/formatters/ubs_credit_formatter.rb +12 -0
- data/lib/ynab_convert/transformers/formatters/wise_formatter.rb +35 -0
- data/lib/ynab_convert/transformers.rb +18 -0
- data/lib/ynab_convert/validators/ynab4_row_validator.rb +83 -0
- data/lib/ynab_convert/validators.rb +9 -0
- data/lib/ynab_convert/version.rb +1 -1
- data/lib/ynab_convert.rb +22 -3
- data/ynab_convert.gemspec +4 -0
- metadata +94 -10
- data/.travis.yml +0 -20
- data/lib/ynab_convert/processor/base.rb +0 -226
- data/lib/ynab_convert/processor/example.rb +0 -124
- data/lib/ynab_convert/processor/n26.rb +0 -70
- data/lib/ynab_convert/processor/revolut.rb +0 -103
- data/lib/ynab_convert/processor/ubs_chequing.rb +0 -137
- data/lib/ynab_convert/processor/ubs_credit.rb +0 -83
@@ -1,83 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Processor
|
4
|
-
# Processes CSV files from UBS Credit Cards Switzerland
|
5
|
-
class UbsCredit < Processor::Base
|
6
|
-
# @option options [String] :file Path to the CSV file to process
|
7
|
-
def initialize(options)
|
8
|
-
register_custom_converters
|
9
|
-
@loader_options = {
|
10
|
-
col_sep: ';',
|
11
|
-
converters: %i[amounts transaction_dates],
|
12
|
-
quote_char: nil,
|
13
|
-
encoding: "#{Encoding::ISO_8859_1}:#{Encoding::UTF_8}",
|
14
|
-
headers: true,
|
15
|
-
# CSV FTW, the first line in these files is not the headers but the
|
16
|
-
# separator specification
|
17
|
-
skip_lines: 'sep=;'
|
18
|
-
}
|
19
|
-
@institution_name = 'UBS (Credit cards)'
|
20
|
-
|
21
|
-
super(options)
|
22
|
-
end
|
23
|
-
|
24
|
-
protected
|
25
|
-
|
26
|
-
def transformers(row)
|
27
|
-
unless row[headers[:transaction_date]].nil?
|
28
|
-
date = row[headers[:transaction_date]].strftime('%d/%m/%Y')
|
29
|
-
end
|
30
|
-
payee = row[headers[:payee]]
|
31
|
-
unless row[headers[:debit]].nil?
|
32
|
-
debit = format('%<amount>.2f', amount: row[headers[:debit]])
|
33
|
-
end
|
34
|
-
unless row[headers[:credit]].nil?
|
35
|
-
credit = format('%<amount>.2f', amount: row[headers[:credit]])
|
36
|
-
end
|
37
|
-
|
38
|
-
converted_row = [date, payee, nil, debit, credit]
|
39
|
-
logger.debug "Converted row: #{converted_row}"
|
40
|
-
converted_row
|
41
|
-
end
|
42
|
-
|
43
|
-
private
|
44
|
-
|
45
|
-
def extract_header_names(row)
|
46
|
-
headers[:transaction_date] ||= row.headers[3]
|
47
|
-
headers[:payee] ||= row.headers[4]
|
48
|
-
headers[:debit] ||= row.headers[10]
|
49
|
-
headers[:credit] ||= row.headers[11]
|
50
|
-
end
|
51
|
-
|
52
|
-
def register_custom_converters
|
53
|
-
CSV::Converters[:amounts] = lambda { |s|
|
54
|
-
# Regex checks if string has only digits, apostrophes, and ends with a
|
55
|
-
# dot and two digits
|
56
|
-
amount_regex = /^[\d'?]+(\.\d{2})$/
|
57
|
-
|
58
|
-
if !s.nil? && s.match(amount_regex)
|
59
|
-
amount = s.delete("'") .to_f
|
60
|
-
logger.debug "Converted `#{s}' into amount `#{amount}'"
|
61
|
-
return amount
|
62
|
-
end
|
63
|
-
|
64
|
-
logger.debug "Not an amount, not parsing `#{s.inspect}'"
|
65
|
-
s
|
66
|
-
}
|
67
|
-
|
68
|
-
CSV::Converters[:transaction_dates] = lambda { |s|
|
69
|
-
date_regex = /^\d{2}\.\d{2}\.\d{4}$/
|
70
|
-
|
71
|
-
if !s.nil? && s.match(date_regex)
|
72
|
-
parsed_date = Date.parse(s)
|
73
|
-
logger.debug "Converted `#{s.inspect}' into date "\
|
74
|
-
"`#{parsed_date}'"
|
75
|
-
parsed_date
|
76
|
-
else
|
77
|
-
logger.debug "Not a date, not parsing #{s.inspect}"
|
78
|
-
s
|
79
|
-
end
|
80
|
-
}
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|