Class: ExtrasDeCont::Rules::Revolut
- Defined in:
- lib/extras_de_cont/rules/revolut.rb
Overview
Rules for parsing Revolut bank statements.
Constant Summary collapse
- SECTION_HEADERS =
[ "Pending from ", "Account transactions from ", "Reverted from ", "Deposit transactions from ", "Transactions from " ].freeze
- DOCUMENT_NOISE_HEADERS =
[ "Account statement", "Balance summary", "The balance on your statement might differ", "There were no transactions during this period", "Transaction types", "Your funds are held and protected by a licensed bank", "Report lost or stolen card", "+", "Get help directly in app", "Get help directly In app", "Scan the QR code", "RON Statement", " Statement", "Generated on the ", "Revolut Bank UAB", "© " ].freeze
- CURRENCY_SYMBOLS =
{ "$" => "USD", "€" => "EUR", "£" => "GBP", "zł" => "PLN", "Kč" => "CZK", "Ft" => "HUF", "лв" => "BGN", "₺" => "TRY", "₴" => "UAH" }.freeze
- DATE_FORMATS =
["%b %e, %Y", "%e %b %Y"].freeze
- DATE_PREFIX =
/\A(?<date>(?:[A-Z][a-z]{2} \d{1,2}, \d{4}|\d{1,2} [A-Z][a-z]{2} \d{4}))\b/- NUMBER =
/-?(?:\d{1,3}(?:[ ,]\d{3})+|\d+)\.\d{2}/- CURRENCY_SYMBOL =
Regexp.union(CURRENCY_SYMBOLS.keys.sort_by { |symbol| -symbol.length })
- AMOUNT =
/(?:#{NUMBER} [A-Z]{3}|#{CURRENCY_SYMBOL}#{NUMBER}|#{NUMBER} ?#{CURRENCY_SYMBOL})/
Instance Method Summary collapse
Instance Method Details
#parse(text) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/extras_de_cont/rules/revolut.rb', line 54 def parse(text) transactions = [] current_table = nil current_lines = [] each_normalized_line(text) do |line| if table_header?(line) flush_transaction(current_lines, transactions, current_table) current_table = extract_table(line) next end if document_noise?(line) flush_transaction(current_lines, transactions, current_table) next end if section_header?(line) flush_transaction(current_lines, transactions, current_table) current_table = nil next end next if ignorable_line?(line) next if current_table.nil? if line.match?(DATE_PREFIX) flush_transaction(current_lines, transactions, current_table) current_lines = [line] elsif current_lines.any? current_lines << line end end flush_transaction(current_lines, transactions, current_table) transactions end |