Class: UOB::Payroll::TXTFile::Footer

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model, PhUtility::TxtData::TxtDataRowDSL
Defined in:
lib/uob/payroll/txt_file/footer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(total_amount:, header:, rows:) ⇒ Footer

Returns a new instance of Footer.

Parameters:

  • total_amount (BigDecimal)

    The total amount to be transferred

  • header (TXTFile::Header)

    The header details used for the hash computation

  • rows (Array<TXTFile::Row>)

    The row details used for the has computation

Raises:



22
23
24
25
26
27
28
# File 'lib/uob/payroll/txt_file/footer.rb', line 22

def initialize(total_amount:, header:, rows:)
  @total_amount = total_amount
  @number_of_records = rows.count
  @header = header
  @rows = rows
  raise Errors::Invalid, errors.full_messages.to_sentence unless valid?
end

Instance Attribute Details

#headerObject (readonly)

Returns the value of attribute header.



17
18
19
# File 'lib/uob/payroll/txt_file/footer.rb', line 17

def header
  @header
end

#number_of_recordsObject (readonly)

Returns the value of attribute number_of_records.



17
18
19
# File 'lib/uob/payroll/txt_file/footer.rb', line 17

def number_of_records
  @number_of_records
end

#rowsObject (readonly)

Returns the value of attribute rows.



17
18
19
# File 'lib/uob/payroll/txt_file/footer.rb', line 17

def rows
  @rows
end

#total_amountObject (readonly)

Returns the value of attribute total_amount.



17
18
19
# File 'lib/uob/payroll/txt_file/footer.rb', line 17

def total_amount
  @total_amount
end

Instance Method Details

#formatted_number_of_recordsObject



34
35
36
# File 'lib/uob/payroll/txt_file/footer.rb', line 34

def formatted_number_of_records
  format '%06d', number_of_records
end

#formatted_total_amountObject



38
39
40
# File 'lib/uob/payroll/txt_file/footer.rb', line 38

def formatted_total_amount
  (format '%015.2f', total_amount).gsub('.','')
end

#hash_totalObject



30
31
32
# File 'lib/uob/payroll/txt_file/footer.rb', line 30

def hash_total
  HashCalculator.calculate(header: header, rows: rows)
end