Class: UkAccountValidator::Validators::StandardModulus
- Inherits:
-
BaseValidator
- Object
- BaseValidator
- UkAccountValidator::Validators::StandardModulus
- Defined in:
- lib/uk_account_validator/validators/standard_modulus.rb
Overview
Perform validation for sort codes with MOD10
Constant Summary
Constants included from NumberIndices
Instance Attribute Summary
Attributes inherited from BaseValidator
#account_number, #exception, #modulus_weight, #sort_code
Instance Method Summary collapse
Methods inherited from BaseValidator
#applying_exceptions, #initialize
Constructor Details
This class inherits a constructor from UkAccountValidator::Validators::BaseValidator
Instance Method Details
#modulus ⇒ Object
5 6 7 |
# File 'lib/uk_account_validator/validators/standard_modulus.rb', line 5 def modulus fail NotImplementedError end |
#valid? ⇒ Boolean
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/uk_account_validator/validators/standard_modulus.rb', line 9 def valid? test_string = sort_code + account_number test_digits = test_string.split(//).map(&:to_i) total = (test_digits) do NUMBER_INDEX.each_pair.reduce(0) do |t, pair| weight, index = pair t + modulus_weight.send(weight) * test_digits[index] end end if exception.override_test? return exception.test(modulus, total, test_digits, :standard_modulus) end total % modulus == 0 end |