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 = []
date_line = nil
each_normalized_line(text) do |line|
if line.start_with?("Valuta / Currency")
current_currency = line.split.last
next
end
if (line)
try_flush(date_line, above_lines, below_lines, current_table, current_currency, transactions)
current_table = extract_columns(line)
above_lines = []
below_lines = []
date_line = nil
next
end
if noise?(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
below_lines << line
else
above_lines << line
end
end
try_flush(date_line, above_lines, below_lines, current_table, current_currency, transactions)
transactions
end
|