module NgBankParser::FirstbankPdfHelpers
Public Instance Methods
contains_account_data?()
click to toggle source
# File lib/ng-bank-parser/parsers/firstbank-pdf-parser/helpers.rb, line 96 def contains_account_data? get_account_data @@account_name && @@account_number && @@last_balance && @@statement_period end
contains_transactions_table?()
click to toggle source
# File lib/ng-bank-parser/parsers/firstbank-pdf-parser/helpers.rb, line 91 def contains_transactions_table? get_transaction_data end
error_message(msg)
click to toggle source
# File lib/ng-bank-parser/parsers/firstbank-pdf-parser/helpers.rb, line 143 def error_message msg return { status: 400, message: msg } end
get_account_data()
click to toggle source
# File lib/ng-bank-parser/parsers/firstbank-pdf-parser/helpers.rb, line 52 def get_account_data lines = get_first_page_text @@pdf_reader lines.each do |line| if line[0].start_with? 'Account No:' set_account_number line set_last_balance line elsif line[0].start_with? 'Account Name:' set_account_name line elsif line[0].start_with? 'For the Period of:' set_statement_period line end end end
get_account_name()
click to toggle source
# File lib/ng-bank-parser/parsers/firstbank-pdf-parser/helpers.rb, line 72 def get_account_name @@account_name end
get_account_number()
click to toggle source
# File lib/ng-bank-parser/parsers/firstbank-pdf-parser/helpers.rb, line 67 def get_account_number @@account_number end
get_from_date()
click to toggle source
# File lib/ng-bank-parser/parsers/firstbank-pdf-parser/helpers.rb, line 81 def get_from_date Date.strptime(@@from_date.strip,"%d-%b-%Y") end
get_last_balance()
click to toggle source
# File lib/ng-bank-parser/parsers/firstbank-pdf-parser/helpers.rb, line 77 def get_last_balance @@last_balance.to_i end
get_to_date()
click to toggle source
# File lib/ng-bank-parser/parsers/firstbank-pdf-parser/helpers.rb, line 86 def get_to_date Date.strptime(@@to_date.strip,"%d-%b-%Y") end
get_transaction_data()
click to toggle source
# File lib/ng-bank-parser/parsers/firstbank-pdf-parser/helpers.rb, line 46 def get_transaction_data pages = get_pages @@pdf_reader get_all_transactions(pages) end
get_unlocked_pdf?(path, password)
click to toggle source
# File lib/ng-bank-parser/parsers/firstbank-pdf-parser/helpers.rb, line 28 def get_unlocked_pdf? path, password response = PDFUnlocker.unlock(path, password) return false unless response if response.include? 'Unlock Failed' return false else pseudo_file = StringIO.new pseudo_file.write(response) begin @@pdf_reader = PDF::Reader.new(pseudo_file) return true rescue return false end end end
has_encryption?(file)
click to toggle source
# File lib/ng-bank-parser/parsers/firstbank-pdf-parser/helpers.rb, line 19 def has_encryption? file begin @@pdf_reader = PDF::Reader.new(file) false rescue PDF::Reader::EncryptedPDFError true end end
is_row_invalid?(row)
click to toggle source
# File lib/ng-bank-parser/parsers/firstbank-pdf-parser/helpers.rb, line 135 def is_row_invalid? row row.length == 0 || row[0].start_with?('END OF STATEMENT') || row[0] == ('Balance B/F') || row[0].start_with?('Page') end
is_transaction_row?(row)
click to toggle source
# File lib/ng-bank-parser/parsers/firstbank-pdf-parser/helpers.rb, line 130 def is_transaction_row? row row[0] =~ /(\d\d-[a-zA-Z]{3}-\d\d)/ end
send_response(data)
click to toggle source
# File lib/ng-bank-parser/parsers/firstbank-pdf-parser/helpers.rb, line 151 def send_response data return { status: 200, data: data } end
set_account_name(line)
click to toggle source
# File lib/ng-bank-parser/parsers/firstbank-pdf-parser/helpers.rb, line 107 def set_account_name line @@account_name = line[1] unless line[1].blank? end
set_account_number(line)
click to toggle source
# File lib/ng-bank-parser/parsers/firstbank-pdf-parser/helpers.rb, line 102 def set_account_number line @@account_number = line[1] unless line[1].blank? end
set_last_balance(line)
click to toggle source
# File lib/ng-bank-parser/parsers/firstbank-pdf-parser/helpers.rb, line 112 def set_last_balance line @@last_balance = line[2] unless line[1].blank? end
set_statement_period(line)
click to toggle source
# File lib/ng-bank-parser/parsers/firstbank-pdf-parser/helpers.rb, line 122 def set_statement_period line unless line[1].blank? @@statement_period = line[1].split('to') @@from_date, @@to_date = @@statement_period end end
update_last_balance(balance)
click to toggle source
# File lib/ng-bank-parser/parsers/firstbank-pdf-parser/helpers.rb, line 117 def update_last_balance balance @@last_balance = balance end
Private Instance Methods
get_all_transactions(pages)
click to toggle source
# File lib/ng-bank-parser/parsers/firstbank-pdf-parser/helpers.rb, line 161 def get_all_transactions pages raw_transactions = [[]] pages.each do |page| page_text = get_page_text page index = get_transaction_table_index page_text unless index == -1 lines = page_text[index..-1] lines.each do |line| raw_transactions << line.strip.split(/\s\s+/) end end end return raw_transactions end