Module: ExtrasDeCont

Defined in:
lib/extras_de_cont.rb,
lib/extras_de_cont/parser.rb,
lib/extras_de_cont/rules/brd.rb,
lib/extras_de_cont/rules/ing.rb,
lib/extras_de_cont/rules/base.rb,
lib/extras_de_cont/transaction.rb,
lib/extras_de_cont/rules/revolut.rb,
lib/extras_de_cont/rules/unicredit.rb,
lib/extras_de_cont/rules/revolut_csv.rb

Overview

The ExtrasDeCont module contains utilities for parsing bank statements.

Defined Under Namespace

Modules: Rules Classes: Parser, Transaction

Constant Summary collapse

BANK_RULES =

Map of supported banks (symbol → rule class)

{
  brd: ExtrasDeCont::Rules::Brd,
  ing: ExtrasDeCont::Rules::Ing,
  revolut: ExtrasDeCont::Rules::Revolut,
  revolut_csv: ExtrasDeCont::Rules::RevolutCsv,
  unicredit: ExtrasDeCont::Rules::UniCredit
}.freeze
RAW_TEXT_BANKS =
%i[revolut_csv].freeze

Class Method Summary collapse

Class Method Details

.parse(file, bank:, exclude: []) ⇒ Array<ExtrasDeCont::Transaction>

Parses a bank statement and returns structured transactions.

Parameters:

  • file (String, Pathname, IO)

    path to the PDF file or an IO-like object

  • bank (Symbol)

    the bank identifier (:unicredit, :revolut, :revolut_csv, etc.)

  • exclude (Array<String, Transaction>) (defaults to: [])

    deduplication keys or transactions already imported

Returns:

Raises:

  • (ArgumentError)

    if the bank is not supported



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/extras_de_cont.rb', line 32

def parse(file, bank:, exclude: [])
  bank = bank.to_sym
  rule_class = BANK_RULES[bank]
  raise ArgumentError, "Unsupported bank: #{bank}. Supported banks: #{BANK_RULES.keys.join(", ")}" unless rule_class

  transactions =
    if RAW_TEXT_BANKS.include?(bank)
      rule_class.new.parse(read_raw_file(file))
    else
      ExtrasDeCont::Parser.new(file).parse_with(rule_class.new)
    end

  deduplicate(transactions, exclude, within_file: RAW_TEXT_BANKS.include?(bank))
end