Class: UOB::Payroll::HashCalculator
- Inherits:
-
Object
- Object
- UOB::Payroll::HashCalculator
- Defined in:
- lib/uob/payroll/hash_calculator.rb
Instance Attribute Summary collapse
-
#header ⇒ Object
readonly
Returns the value of attribute header.
-
#rows ⇒ Object
readonly
Returns the value of attribute rows.
Class Method Summary collapse
Instance Method Summary collapse
- #calculate ⇒ Object
-
#initialize(header:, rows:) ⇒ HashCalculator
constructor
A new instance of HashCalculator.
- #sum_header ⇒ Object
- #sum_rows ⇒ Object
Constructor Details
#initialize(header:, rows:) ⇒ HashCalculator
Returns a new instance of HashCalculator.
16 17 18 19 |
# File 'lib/uob/payroll/hash_calculator.rb', line 16 def initialize(header:, rows:) @header = header @rows = rows end |
Instance Attribute Details
#header ⇒ Object (readonly)
Returns the value of attribute header.
26 27 28 |
# File 'lib/uob/payroll/hash_calculator.rb', line 26 def header @header end |
#rows ⇒ Object (readonly)
Returns the value of attribute rows.
26 27 28 |
# File 'lib/uob/payroll/hash_calculator.rb', line 26 def rows @rows end |
Class Method Details
.calculate(header:, rows:) ⇒ Object
11 12 13 |
# File 'lib/uob/payroll/hash_calculator.rb', line 11 def calculate(header:, rows:) new(header: header, rows: rows).calculate end |
Instance Method Details
#calculate ⇒ Object
21 22 23 24 |
# File 'lib/uob/payroll/hash_calculator.rb', line 21 def calculate sum_header + sum_rows end |
#sum_header ⇒ Object
28 29 30 31 32 |
# File 'lib/uob/payroll/hash_calculator.rb', line 28 def sum_header calculate_string(header.originating_bic_code) + calculate_padded_string(string: header.originating_account_number, size: 34) + calculate_padded_string(string: sanitize(header.originating_account_name), size: 140) end |
#sum_rows ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/uob/payroll/hash_calculator.rb', line 34 def sum_rows hash_code = 0 sum = 0 rows.each.map do |row| hash_code = 0 if hash_code == 9 hash_code += 1 sum += calculate_string(row.receiving_bic_code) + hash_code * calculate_padded_string(string: row.receiving_account_number, size: 34) + hash_code * calculate_padded_string(string: sanitize(row.receiving_account_name), size: 140) + calculate_payment_type(hash_code) + calculate_string('SGD') + calculate_padded_string(string: row.formatted_amount, size: 18, pad: '0', just: :right) + calculate_string('SALA') end sum end |