class UOB::Payroll::TXTFile
Attributes
header[RW]
rows[RW]
Public Class Methods
new(company_name:, account_number:, branch_code:, date:, payable_date:, transactions:)
click to toggle source
# File lib/uob/payroll/txt_file.rb, line 14 def initialize(company_name:, account_number:, branch_code:, date:, payable_date:, transactions:) @header = Header.new( company_name: company_name, account_number: account_number, branch_code: branch_code, creation_date: date, value_date: payable_date ) @rows = transactions.map { |transaction| Row.new transaction } @footer = Footer.new total_amount: total_amount(rows), header: header, rows: rows end
Public Instance Methods
content()
click to toggle source
# File lib/uob/payroll/txt_file.rb, line 26 def content [ header, rows, footer, ].join("\n") end
Private Instance Methods
total_amount(rows)
click to toggle source
We need to round each amount first before summing them up so that it matches the amounts in the details
# File lib/uob/payroll/txt_file.rb, line 38 def total_amount(rows) rows.each.map { |row| row.amount.round(2) }.reduce(0, :+) end