module NgBankParser::HbTransactionHelpers

Public Instance Methods

pdf_is_valid?(file) click to toggle source
# File lib/ng-bank-parser/parsers/hb-pdf-parser/hb_transaction_helpers.rb, line 6
def pdf_is_valid?(file)
  has_transaction_page? && has_transaction_columns? && has_correct_rc_number? && !has_encryption?(file)
end

Private Instance Methods

create_transaction(line, type) click to toggle source
# File lib/ng-bank-parser/parsers/hb-pdf-parser/hb_transaction_helpers.rb, line 67
def create_transaction(line, type)
  transaction = set_transaction_attr(line)
  set_transaction_type(transaction, type, line)
  @transactions << transaction
end
credit_amount(line) click to toggle source
# File lib/ng-bank-parser/parsers/hb-pdf-parser/hb_transaction_helpers.rb, line 103
def credit_amount(line)
  line[TRANSACTION_CREDIT..TRANSACTION_CREDIT_END].get_numbers
end
debit_amount(line) click to toggle source
# File lib/ng-bank-parser/parsers/hb-pdf-parser/hb_transaction_helpers.rb, line 99
def debit_amount(line)
  line[TRANSACTION_DEBIT..TRANSACTION_DEBIT_END].get_numbers
end
has_correct_rc_number?() click to toggle source
# File lib/ng-bank-parser/parsers/hb-pdf-parser/hb_transaction_helpers.rb, line 16
def has_correct_rc_number?
  @reader.pages.first.text.remove_empty_lines.lines.first.strip == CORRECT_RC_NUMBER
end
has_encryption?(file) click to toggle source
# File lib/ng-bank-parser/parsers/hb-pdf-parser/hb_transaction_helpers.rb, line 24
def has_encryption?(file)
  begin
    @reader = PDF::Reader.new(file)
    false
  rescue PDF::Reader::EncryptedPDFError
    true
  end
end
has_transaction_columns?() click to toggle source
# File lib/ng-bank-parser/parsers/hb-pdf-parser/hb_transaction_helpers.rb, line 20
def has_transaction_columns?
  @reader.pages[SECOND_PAGE_INDEX].text.remove_empty_lines.lines[TRANSACTION_HEADER_INDEX].remove_white_spaces == COLUMN_ARRANGEMENT
end
has_transaction_page?() click to toggle source
# File lib/ng-bank-parser/parsers/hb-pdf-parser/hb_transaction_helpers.rb, line 12
def has_transaction_page?
  @reader.pages[SECOND_PAGE_INDEX].present?
end
set_account_name() click to toggle source
# File lib/ng-bank-parser/parsers/hb-pdf-parser/hb_transaction_helpers.rb, line 33
def set_account_name
  @account_name = @reader.pages[SECOND_PAGE_INDEX].text.remove_empty_lines.lines[ACCOUNT_NAME_LINE_INDEX].get_text_between_markers(ACCOUNT_NAME_FIRST_MAKER, ACCOUNT_NAME_SECOND_MAKER).remove_white_spaces
end
set_account_number() click to toggle source
# File lib/ng-bank-parser/parsers/hb-pdf-parser/hb_transaction_helpers.rb, line 37
def set_account_number
  @account_number = @reader.pages[SECOND_PAGE_INDEX].text.remove_empty_lines.lines[ACCOUNT_NUMBER_LINE_INDEX].strip.get_text_after_marker(ACCOUNT_NUMBER_MAKER).remove_white_spaces
end
set_end_date() click to toggle source
# File lib/ng-bank-parser/parsers/hb-pdf-parser/hb_transaction_helpers.rb, line 41
def set_end_date
  @end_date = Date.parse(@reader.pages[SECOND_PAGE_INDEX].text.remove_empty_lines.lines[DURATION_DATE_LINE_INDEX].get_text_after_marker(END_DATE_MAKER).remove_white_spaces)
end
set_start_date() click to toggle source
# File lib/ng-bank-parser/parsers/hb-pdf-parser/hb_transaction_helpers.rb, line 45
def set_start_date
  @start_date = Date.parse(@reader.pages[SECOND_PAGE_INDEX].text.remove_empty_lines.lines[DURATION_DATE_LINE_INDEX].get_text_between_markers(' ', END_DATE_MAKER).remove_white_spaces)
end
set_transaction_attr(line) click to toggle source
# File lib/ng-bank-parser/parsers/hb-pdf-parser/hb_transaction_helpers.rb, line 49
def set_transaction_attr(line)
  transaction_object = {}
  transaction_object[:date] = transaction_date(line)

  transaction_object[:balance] = transaction_balance(line)
  transaction_object[:remarks] = transaction_remarks(line)
  transaction_object[:ref] = transaction_reference(line)
  transaction_object
end
set_transaction_type(transaction, type, line) click to toggle source
# File lib/ng-bank-parser/parsers/hb-pdf-parser/hb_transaction_helpers.rb, line 73
def set_transaction_type(transaction, type, line)
  if type == 'debit'
    transaction[:amount] = debit_amount(line)
    transaction[:type] = type
  elsif type == 'credit'
    transaction[:amount] = credit_amount(line)
    transaction[:type] = type
  end
end
transaction_balance(line) click to toggle source
# File lib/ng-bank-parser/parsers/hb-pdf-parser/hb_transaction_helpers.rb, line 87
def transaction_balance(line)
  line[TRANSACTION_BALANCE..TRANSACTION_BALANCE_END].get_numbers
end
transaction_date(line) click to toggle source
# File lib/ng-bank-parser/parsers/hb-pdf-parser/hb_transaction_helpers.rb, line 83
def transaction_date(line)
  Date.parse(line[0..19].remove_white_spaces)
end
transaction_is_a_credit?(transaction_items_list, line) click to toggle source
# File lib/ng-bank-parser/parsers/hb-pdf-parser/hb_transaction_helpers.rb, line 63
def transaction_is_a_credit?(transaction_items_list, line)
  transaction_items_list[TRANSACTION_CREDIT_INDEX] && credit_amount(line) > 0.00
end
transaction_is_a_debit?(transaction_items_list, line) click to toggle source
# File lib/ng-bank-parser/parsers/hb-pdf-parser/hb_transaction_helpers.rb, line 59
def transaction_is_a_debit?(transaction_items_list, line)
  transaction_items_list[TRANSACTION_DEBIT_INDEX] && debit_amount(line) > 0.00
end
transaction_items(line) click to toggle source
# File lib/ng-bank-parser/parsers/hb-pdf-parser/hb_transaction_helpers.rb, line 108
def transaction_items(line)
  line.strip.split("   ").reject(&:empty?)
end
transaction_reference(line) click to toggle source
# File lib/ng-bank-parser/parsers/hb-pdf-parser/hb_transaction_helpers.rb, line 95
def transaction_reference(line)
  line[TRANSACTION_REFERENCE..TRANSACTION_REFERENCE_END].remove_white_spaces
end
transaction_remarks(line) click to toggle source
# File lib/ng-bank-parser/parsers/hb-pdf-parser/hb_transaction_helpers.rb, line 91
def transaction_remarks(line)
  line[TRANSACTION_REMARKS..TRANSACTION_REMARKS_END].remove_white_spaces
end