Skip to content

Commit

Permalink
Update ecobank parser to support more edge cases
Browse files Browse the repository at this point in the history
  • Loading branch information
onyekvchi committed Sep 9, 2018
1 parent 75d91be commit 24646d2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
2 changes: 0 additions & 2 deletions lib/ng-bank-parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,4 @@

module NgBankParser
# Your code goes here...
file_path = '/Users/onyekachi/dev/ruby/ng-bank-parser/lib/ng-bank-parser/fixtures/ecobank-pdf-valid.pdf'
@parser = NgBankParser::Router.parse("ecobank", file_path)
end
24 changes: 18 additions & 6 deletions lib/ng-bank-parser/parsers/ecobank-pdf-parser/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,23 @@ def get_transactions(pdf_array)
transaction_hash[:amount] = amount_to_f(transaction[4])
transaction_hash[:balance] = amount_to_f(transaction[5])
elsif transaction.count == 5
transaction_hash[:remarks] = transaction[2]
transaction_hash[:ref] = transaction[3]
amount_and_balance = transaction[4].split(" ")
transaction_hash[:amount] = amount_to_f(amount_and_balance[0])
transaction_hash[:balance] = amount_to_f(amount_and_balance[1])
if transaction[2].chars.first === "'"
transaction_hash[:remarks] = ""
transaction_hash[:ref] = transaction[2]
transaction_hash[:amount] = amount_to_f(transaction[3])
transaction_hash[:balance] = amount_to_f(transaction[4])
elsif transaction[2].split("'")[1]
transaction_hash[:remarks] = transaction[2].split("'")[0]
transaction_hash[:ref] = transaction[2].split("'")[1]
transaction_hash[:amount] = amount_to_f(transaction[3])
transaction_hash[:balance] = amount_to_f(transaction[4])
else
transaction_hash[:remarks] = transaction[2]
transaction_hash[:ref] = transaction[3]
amount_and_balance = transaction[4].split(" ")
transaction_hash[:amount] = amount_to_f(amount_and_balance[0])
transaction_hash[:balance] = amount_to_f(amount_and_balance[1])
end
else
remarks_and_ref = transaction[2].split("'")
transaction_hash[:remarks] = remarks_and_ref[0]
Expand All @@ -89,7 +101,7 @@ def get_transactions(pdf_array)
transaction_hash[:amount] = amount_to_f(amount_and_balance[0])
transaction_hash[:balance] = amount_to_f(amount_and_balance[1])
end

transaction_hash[:type] = transaction_type(transaction_hash[:balance], opening_balance)

opening_balance = transaction_hash[:balance]
Expand Down

0 comments on commit 24646d2

Please sign in to comment.