Class: ExtrasDeCont::Rules::Ing

Inherits:
Base
  • Object
show all
Defined in:
lib/extras_de_cont/rules/ing.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+Detalii tranzactie\s+Debit\s+Credit/
AMOUNT_PATTERN =
/\d{1,3}(?:\.\d{3})*,\d{2}/
NOISE_PATTERNS =
[
  /\AExtras de cont\z/,
  /\APentru perioada:/,
  /\AValabil fara semnatura/,
  /\AING Bank/,
  /\ASediul:/,
  /\ANr\. inregistrare/,
  /\ACIF:/,
  /\ATitular cont:/,
  /\ACNP:/,
  /\AStr\. /,
  /\ATip cont:/,
  /\ANumar cont:/,
  /\AMoneda:/,
  /\A\d{6},/,
  /\ARoxana Petria/,
  /\AAlexandra Ilie/,
  /\AȘef Serviciu/,
  /\ASef Serviciu/,
  /\ASucursala/,
  /\AÎN/,
  /\AInformatii despre/,
  /\Ape www\./,
  /\d+\/\d+$/
].freeze

Instance Method Summary collapse

Instance Method Details

#parse(text) ⇒ Object



49
50
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
# File 'lib/extras_de_cont/rules/ing.rb', line 49

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

  each_normalized_line(text) do |line|
    if line.start_with?("Moneda:")
      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_column_positions(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