Class: Exception5
- Inherits:
-
BaseException
- Object
- BaseException
- Exception5
- Defined in:
- lib/uk_account_validator/exceptions/exception_5.rb
Overview
Perform the first check (standard modulus check) except:
* If the sorting code appears in SCSUBTAB.txt, substitute it for the
"substitute with" column (for check purposes only).
If the sorting code is not found, use the original sorting code.
For the standard check with exception 5 the checkdigit is g from the original account number.
* After dividing the result by 11:
- if the remainder = 0 and g = 0 the account number is valid
- if the remainder = 1 the account number is invalid
- for all other remainders, take the remainder away from 11. If the number
you get is the same as g then the account number is valid.
Perform the second double alternate check, and for the double alternate check with exception 5 the checkdigit is h from the original account number, except:
* After dividing the result by 10:
- if the remainder = 0 and h = 0 the account number is valid
- for all other remainders, take the remainder away from 10. If the number
you get is the same as h then the account number is valid.
Constant Summary
Constants included from NumberIndices
Instance Attribute Summary
Attributes inherited from BaseException
#account_number, #check_number, #modulus_weight, #sort_code
Instance Method Summary collapse
- #apply_sort_code_substitutions ⇒ Object
- #override_test? ⇒ Boolean
- #test(modulus, total, test_digits, test) ⇒ Object
Methods inherited from BaseException
#after_calculate_total, allow_any?, #apply_account_number_substitutions, #initialize, #replace_weight, #zero_all, #zero_u_b
Constructor Details
This class inherits a constructor from BaseException
Instance Method Details
#apply_sort_code_substitutions ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/uk_account_validator/exceptions/exception_5.rb', line 21 def apply_sort_code_substitutions substitutions = UkAccountValidator.read_sort_code_substitution return substitutions[sort_code] if substitutions.keys.include?(sort_code) return sort_code end |
#override_test? ⇒ Boolean
29 30 31 |
# File 'lib/uk_account_validator/exceptions/exception_5.rb', line 29 def override_test? true end |
#test(modulus, total, test_digits, test) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/uk_account_validator/exceptions/exception_5.rb', line 33 def test(modulus, total, test_digits, test) if test == :double_alternate check_digit = :h else check_digit = :g end check_sum = total % modulus expected_sum = test_digits[NUMBER_INDEX[check_digit]].to_i return false if check_sum == 1 && check_digit == :g return true if check_sum == 0 && expected_sum == 0 return (modulus - check_sum) == expected_sum end |