Class: ExtrasDeCont::Rules::UniCredit
- Defined in:
- lib/extras_de_cont/rules/unicredit.rb
Constant Summary collapse
- ROMANIAN_MONTHS =
{ "ianuarie" => 1, "februarie" => 2, "martie" => 3, "aprilie" => 4, "mai" => 5, "iunie" => 6, "iulie" => 7, "august" => 8, "septembrie" => 9, "octombrie" => 10, "noiembrie" => 11, "decembrie" => 12 }.freeze
- RO_MONTH_NAMES =
ROMANIAN_MONTHS.keys.freeze
- DATE_PATTERN =
/\b(\d{1,2})\s+(#{RO_MONTH_NAMES.join("|")})\s+(\d{4})\b/i- DATE_PREFIX =
/\A\s*#{DATE_PATTERN}/- TABLE_HEADER_PATTERN =
/Data\s+Descriere\s+Debit\s+Credit\s+Sold/- SECTION_HEADERS =
[ "TRANZACȚII", "SUMAR CONT", "EXTRAS DE CONT" ].freeze
- NOISE_PATTERNS =
[ /\AUniCredit Bank S\.A\./, /\ABulevardul/, /\ASector \d/, /\ATel:/, /\AEmail:/, /\Aunicredit\.ro/, /\ACapital social:/, /\APrezentul extras/, /\AFondurile disponibile/, /\APentru mai multe/, /\ANUME CLIENT:/, /\AADRESA:/, /\ASUCURSALA:/, /\ADATA EXTRAS CONT/, /\APERIOADA/, /\ATIP CONT:/, /\AIBAN:/, /\AMONEDA:/, /\AOperator de date/, /\ASold inițial/, /\ASold final/, /\AOperator de date cu/ ].freeze
- NEW_TRANSACTION_MARKERS =
[ /\A\+CMS CLT-/, /\A\+GPP/, /\APlata electronica/, /\APlata Instant/, /\AIncasare Instant/, /\ATransfer electronic/ ].freeze
- AMOUNT_PATTERN =
/\d{1,3}(?:[.,]\d{3})*\.\d{2}/- CURRENCY_FROM_HEADER =
/Sold\(([A-Z]{3})\)/
Instance Method Summary collapse
Instance Method Details
#parse(text) ⇒ Object
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 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/extras_de_cont/rules/unicredit.rb', line 64 def parse(text) transactions = [] current_currency = nil current_table = nil above_lines = [] below_lines = [] date_line = nil each_normalized_line(text) do |line| if (m = line.match(CURRENCY_FROM_HEADER)) current_currency = m[1] end if table_header?(line) try_flush(date_line, above_lines, below_lines, current_table, current_currency, transactions) current_table = extract_column_positions(line) above_lines, below_lines, date_line = [], [], nil next end if noise?(line) || section_header?(line) try_flush(date_line, above_lines, below_lines, current_table, current_currency, transactions) above_lines, below_lines, date_line = [], [], nil next end next if current_table.nil? if date_line?(line) try_flush(date_line, above_lines, below_lines, current_table, current_currency, transactions) date_line = line below_lines = [] next end if date_line if new_transaction_marker?(line) try_flush(date_line, above_lines, below_lines, current_table, current_currency, transactions) date_line, below_lines = nil, [] above_lines = [line] else below_lines << line end else above_lines << line end end try_flush(date_line, above_lines, below_lines, current_table, current_currency, transactions) transactions end |