Skip to content

Commit

Permalink
Merge pull request #18 from onyekvchi/feature/ecobank-parser
Browse files Browse the repository at this point in the history
Feature/ecobank parser
  • Loading branch information
fathermerry authored Sep 10, 2018
2 parents 1435fb2 + 2b71491 commit 92e93e3
Show file tree
Hide file tree
Showing 10 changed files with 272 additions and 55 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ build/

# for a library or gem, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# Gemfile.lock
Gemfile.lock
# .ruby-version
# .ruby-gemset

Expand Down
82 changes: 42 additions & 40 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11,64 +11,66 @@ PATH
GEM
remote: https://rubygems.org/
specs:
Ascii85 (1.0.2)
activesupport (4.2.4)
i18n (~> 0.7)
json (~> 1.7, >= 1.7.7)
Ascii85 (1.0.3)
activesupport (5.2.1)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 0.7, < 2)
minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
afm (0.2.2)
diff-lcs (1.2.5)
domain_name (0.5.25)
concurrent-ruby (1.0.5)
diff-lcs (1.3)
domain_name (0.5.20180417)
unf (>= 0.0.5, < 1.0.0)
hashery (2.1.1)
http-cookie (1.0.2)
hashery (2.1.2)
http-cookie (1.0.3)
domain_name (~> 0.5)
i18n (0.7.0)
json (1.8.3)
mime-types (2.99)
mini_portile2 (2.0.0)
minitest (5.8.3)
i18n (1.1.0)
concurrent-ruby (~> 1.0)
mime-types (3.2.2)
mime-types-data (~> 3.2015)
mime-types-data (3.2018.0812)
mini_portile2 (2.3.0)
minitest (5.11.3)
netrc (0.11.0)
nokogiri (1.6.7)
mini_portile2 (~> 2.0.0.rc2)
pdf-reader (1.3.3)
nokogiri (1.8.4)
mini_portile2 (~> 2.3.0)
pdf-reader (2.1.0)
Ascii85 (~> 1.0.0)
afm (~> 0.2.0)
afm (~> 0.2.1)
hashery (~> 2.0)
ruby-rc4
ttfunk
rake (10.4.2)
rest-client (1.8.0)
rake (10.5.0)
rest-client (2.0.2)
http-cookie (>= 1.0.2, < 2.0)
mime-types (>= 1.16, < 3.0)
netrc (~> 0.7)
roo (2.1.1)
mime-types (>= 1.16, < 4.0)
netrc (~> 0.8)
roo (2.7.1)
nokogiri (~> 1)
rubyzip (~> 1.1, < 2.0.0)
rspec (3.3.0)
rspec-core (~> 3.3.0)
rspec-expectations (~> 3.3.0)
rspec-mocks (~> 3.3.0)
rspec-core (3.3.2)
rspec-support (~> 3.3.0)
rspec-expectations (3.3.1)
rspec (3.8.0)
rspec-core (~> 3.8.0)
rspec-expectations (~> 3.8.0)
rspec-mocks (~> 3.8.0)
rspec-core (3.8.0)
rspec-support (~> 3.8.0)
rspec-expectations (3.8.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.3.0)
rspec-mocks (3.3.2)
rspec-support (~> 3.8.0)
rspec-mocks (3.8.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.3.0)
rspec-support (3.3.0)
rspec-support (~> 3.8.0)
rspec-support (3.8.0)
ruby-rc4 (0.1.5)
rubyzip (1.1.7)
thread_safe (0.3.5)
ttfunk (1.4.0)
tzinfo (1.2.2)
rubyzip (1.2.2)
thread_safe (0.3.6)
ttfunk (1.5.1)
tzinfo (1.2.5)
thread_safe (~> 0.1)
unf (0.1.4)
unf_ext
unf_ext (0.0.7.1)
unf_ext (0.0.7.5)

PLATFORMS
ruby
Expand All @@ -80,4 +82,4 @@ DEPENDENCIES
rspec

BUNDLED WITH
1.10.6
1.16.4
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ Heritage Bank:
- key: hb
- supported formats: pdf

Access Bank:
- key: accessbank
- supported formats: pdf

Ecobank:
- key: ecobank
- supported formats: pdf

## Contributing

Documentation on contribution can be found in the contribution wiki
Expand Down
21 changes: 11 additions & 10 deletions lib/ng-bank-parser.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
require "ng-bank-parser/version"
require "ng-bank-parser/banks"
require "ng-bank-parser/router"
require "ng-bank-parser/pdf-unlocker"
require "ng-bank-parser/parsers/gtb-excel-parser"
require "ng-bank-parser/parsers/uba-pdf-parser"
require "ng-bank-parser/parsers/hb-pdf-parser"
require "ng-bank-parser/parsers/firstbank-pdf-parser"
require "ng-bank-parser/parsers/accessbank-pdf-parser"
require_relative "ng-bank-parser/version"
require_relative "ng-bank-parser/banks"
require_relative "ng-bank-parser/router"
require_relative "ng-bank-parser/pdf-unlocker"
require_relative "ng-bank-parser/parsers/gtb-excel-parser"
require_relative "ng-bank-parser/parsers/uba-pdf-parser"
require_relative "ng-bank-parser/parsers/hb-pdf-parser"
require_relative "ng-bank-parser/parsers/firstbank-pdf-parser"
require_relative "ng-bank-parser/parsers/accessbank-pdf-parser"
require_relative "ng-bank-parser/parsers/ecobank-pdf-parser"

module NgBankParser
# Your code goes here...
# Your code goes here...
end
11 changes: 10 additions & 1 deletion lib/ng-bank-parser/banks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ class Banks
invalid: "lib/ng-bank-parser/fixtures/accessbank-pdf-invalid.pdf",
extensions: ["pdf"]
}]
}]
},{
key: "ecobank",
name: "Ecobank Nigeria",
parsers: [{
format: "pdf",
valid: "lib/ng-bank-parser/fixtures/ecobank-pdf-valid.pdf",
invalid: "lib/ng-bank-parser/fixtures/ecobank-pdf-invalid.pdf",
extensions: ["pdf"]
}]
}]
end
end
Binary file not shown.
Binary file added lib/ng-bank-parser/fixtures/ecobank-pdf-valid.pdf
Binary file not shown.
4 changes: 1 addition & 3 deletions lib/ng-bank-parser/parsers/accessbank-pdf-parser/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,6 @@ def get_transactions(pdf_array)
end




def error(msg)
{ status: 400, message: msg }
end
Expand All @@ -122,7 +120,6 @@ def success(data)
end



private
def remove_line_spacing(str)
str.gsub(/^$\n/, '').lines
Expand Down Expand Up @@ -161,6 +158,7 @@ def string_with_dash_to_date(date_str)
Date.strptime(date_str, '%d-%b-%y')
end


def string_with_slash_to_date(date_str)
Date.strptime(date_str, '%d/%m/%Y')
end
Expand Down
35 changes: 35 additions & 0 deletions lib/ng-bank-parser/parsers/ecobank-pdf-parser.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
require 'pdf-reader'
require 'open-uri'
require_relative 'ecobank-pdf-parser/helpers'

module NgBankParser
class EcobankPdf
extend EcobankPdfHelpers

FILE_FORMATS = [".pdf"]

def self.parse(path, password=nil)
unless FILE_FORMATS.include? File.extname(path)
return error("Invalid file format. Please use one of the following: #{ FILE_FORMATS.each{ |format| format }}")
end

file = open(path)
begin
@pdf = PDF::Reader.new(file)
rescue PDF::Reader::EncryptedPDFError
return error("Invalid file. Please use an unencrypted pdf")
rescue
return error("Couldn't parse this file")
end

pdf_array = pdf_to_a(@pdf)

unless has_valid_details?(pdf_array)
return error("Couldn't fetch account details from pdf")
end

response = get_details(pdf_array)
return success(response)
end
end
end
Loading

0 comments on commit 92e93e3

Please sign in to comment.