Class: ExtrasDeCont::Rules::Brd

Inherits:
Base
  • Object
show all
Defined in:
lib/extras_de_cont/rules/brd.rb

Constant Summary collapse

DATE_PREFIX =
/\A(?<date>\d{2}\/\d{2}\/\d{4})\b/
AMOUNT_PATTERN =
/\d{1,3}(?:\.\d{3})*,\d{2}/
TABLE_HEADER_PATTERN =
/Data oper\.\s+Descriere operatiune\s+Debit\s+Credit\s+Data val\./
NOISE_PATTERNS =
[
  /\APag\./,
  /\ABRD-Groupe/,
  /\ACAPITAL SOCIAL/,
  /\AMihalache/,
  /\ATel:/,
  /\ARO361579/,
  /\A255\/06/,
  /\APJR01INCR/,
  /\ACIFRE CHEIE/,
  /\ACONTURI DETINUTE/,
  /\AFonduri proprii/,
  /\ALimita de credit/,
  /\ACredit neutilizat/,
  /\ADescoperit/,
  /\ANr\. Zile/,
  /\ATotal disponibil/,
  /\ATotal sume/,
  /\ADomicilierea contului/,
  /\AReferinte bancare/,
  /\ATitular \/ Account/,
  /\AIBAN /,
  /\ANumar cont/,
  /\AExtras de cont/,
  /\ADe la \/ From/,
  /\ADocumentul este/,
  /\ACNP\/CUI:/,
  /\ASWIFT/,
  /\AAg\. /,
  /\AStr\. /,
  /\A•/,
  /\Ahttp/,
  /\ASold/,
  /\ATotal debit/,
  /\ACard:MBS/,
  /\ATrans\.Date/
].freeze

Instance Method Summary collapse

Instance Method Details

#parse(text) ⇒ Object



51
52
53
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
91
92
93
94
95
96
97
98
99
100
# File 'lib/extras_de_cont/rules/brd.rb', line 51

def parse(text)
  transactions = []
  current_table = nil
  current_currency = nil
  above_lines = []
  below_lines = []
   = nil

  each_normalized_line(text) do |line|
    if line.start_with?("Valuta / Currency")
      current_currency = line.split.last
      next
    end

    if table_header?(line)
      try_flush(, above_lines, below_lines, current_table, current_currency, transactions)
      current_table = extract_columns(line)
      above_lines = []
      below_lines = []
       = nil
      next
    end

    if noise?(line)
      try_flush(, above_lines, below_lines, current_table, current_currency, transactions)
      above_lines = []
      below_lines = []
       = nil
      next
    end

    next if current_table.nil?

    if (line)
      try_flush(, above_lines, below_lines, current_table, current_currency, transactions)
       = line
      below_lines = []
      next
    end

    if 
      below_lines << line
    else
      above_lines << line
    end
  end

  try_flush(, above_lines, below_lines, current_table, current_currency, transactions)
  transactions
end