Class: ChinaBank::PayrollTextFile::File

Inherits:
Object
  • Object
show all
Defined in:
lib/china_bank/payroll_text_file/file.rb

Overview

Describes the payroll text file’s content including the lines that builds it.

Instance Method Summary collapse

Constructor Details

#initialize(account_number:, account_type: "00", bank_code: "888", transactions: []) ⇒ File

Returns a new instance of File.

Parameters:

  • account_number (String)
  • account_type (String) (defaults to: "00")
  • bank_code (String) (defaults to: "888")
  • transactions (Array<Hash>) (defaults to: [])


11
12
13
14
15
16
# File 'lib/china_bank/payroll_text_file/file.rb', line 11

def initialize(account_number:, account_type: "00", bank_code: "888", transactions: [])
  @account_number = 
  @account_type = 
  @bank_code = bank_code
  @transactions = transactions
end

Instance Method Details

#contentString

Returns:

  • (String)


19
20
21
# File 'lib/china_bank/payroll_text_file/file.rb', line 19

def content
  (credit_lines + [debit_line]).join(new_line) + new_line
end

#credit_linesArray<ChinaBank::PayrollTextFile::Line>

Returns Array<ChinaBank::PayrollTextFile::Line>.

Returns:



24
25
26
# File 'lib/china_bank/payroll_text_file/file.rb', line 24

def credit_lines
  transactions.map { |transaction| Line.new **transaction.merge(transaction_type: Line::TYPES[:credit]) }
end

#debit_lineChinaBank::PayrollTextFile::Line



29
30
31
32
33
34
35
# File 'lib/china_bank/payroll_text_file/file.rb', line 29

def debit_line
  Line.new account_number: ,
           account_type: ,
           bank_code: bank_code,
           transaction_type: Line::TYPES[:debit],
           amount: total
end