uk_account_validator_auctionet 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/.rubocop.yml +11 -0
- data/.travis.yml +14 -0
- data/Gemfile +14 -0
- data/LICENSE.txt +23 -0
- data/README.md +51 -0
- data/Rakefile +11 -0
- data/data/scsubtab.txt +21 -0
- data/data/valacdos.txt +1074 -0
- data/features/allow_hyphens_in_sort_codes.feature +9 -0
- data/features/exceptions.feature +49 -0
- data/features/invalid_formats.feature +33 -0
- data/features/modulus10.feature +18 -0
- data/features/modulus11.feature +18 -0
- data/features/modulus_weight.feature +26 -0
- data/features/modulus_weights_table.feature +14 -0
- data/features/step_definitions/basics.rb +23 -0
- data/features/step_definitions/modulus_weight.rb +7 -0
- data/features/step_definitions/modulus_weights_table.rb +13 -0
- data/features/support/env.rb +2 -0
- data/features/two_modulus_check.feature +25 -0
- data/lib/uk_account_validator.rb +57 -0
- data/lib/uk_account_validator/backports/array_bsearch_index.rb +33 -0
- data/lib/uk_account_validator/exceptions/base_exception.rb +65 -0
- data/lib/uk_account_validator/exceptions/exception_1.rb +10 -0
- data/lib/uk_account_validator/exceptions/exception_10.rb +18 -0
- data/lib/uk_account_validator/exceptions/exception_12.rb +9 -0
- data/lib/uk_account_validator/exceptions/exception_14.rb +30 -0
- data/lib/uk_account_validator/exceptions/exception_2_9.rb +68 -0
- data/lib/uk_account_validator/exceptions/exception_3.rb +10 -0
- data/lib/uk_account_validator/exceptions/exception_4.rb +16 -0
- data/lib/uk_account_validator/exceptions/exception_5.rb +48 -0
- data/lib/uk_account_validator/exceptions/exception_6.rb +16 -0
- data/lib/uk_account_validator/exceptions/exception_7.rb +9 -0
- data/lib/uk_account_validator/exceptions/exception_8.rb +7 -0
- data/lib/uk_account_validator/modulus_weight.rb +35 -0
- data/lib/uk_account_validator/modulus_weights_table.rb +35 -0
- data/lib/uk_account_validator/number_indices.rb +18 -0
- data/lib/uk_account_validator/validator.rb +92 -0
- data/lib/uk_account_validator/validators/base_validator.rb +28 -0
- data/lib/uk_account_validator/validators/double_alternate.rb +35 -0
- data/lib/uk_account_validator/validators/modulus10.rb +9 -0
- data/lib/uk_account_validator/validators/modulus11.rb +9 -0
- data/lib/uk_account_validator/validators/standard_modulus.rb +30 -0
- data/lib/uk_account_validator/version.rb +3 -0
- data/uk_account_validator.gemspec +22 -0
- metadata +104 -0
@@ -0,0 +1,35 @@
|
|
1
|
+
module UkAccountValidator
|
2
|
+
module Validators
|
3
|
+
# Perform validation for sort codes with MOD10
|
4
|
+
class DoubleAlternate < BaseValidator
|
5
|
+
def modulus
|
6
|
+
10
|
7
|
+
end
|
8
|
+
|
9
|
+
def valid?
|
10
|
+
test_string = @sort_code + @account_number
|
11
|
+
|
12
|
+
test_digits = test_string.split(//).map(&:to_i)
|
13
|
+
|
14
|
+
total = applying_exceptions(test_digits) do
|
15
|
+
# Apply weights
|
16
|
+
weighted_test_digits = NUMBER_INDEX.map do |weight, index|
|
17
|
+
@modulus_weight.send(weight) * test_digits[index]
|
18
|
+
end
|
19
|
+
|
20
|
+
# Split into individual digits by concating then splitting again.
|
21
|
+
weighted_test_digits = weighted_test_digits.join.split(//).map(&:to_i)
|
22
|
+
|
23
|
+
# Now sum
|
24
|
+
weighted_test_digits.inject(:+)
|
25
|
+
end
|
26
|
+
|
27
|
+
if exception.override_test?
|
28
|
+
return exception.test(modulus, total, test_digits, :double_alternate)
|
29
|
+
end
|
30
|
+
|
31
|
+
total % modulus == 0
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module UkAccountValidator
|
2
|
+
module Validators
|
3
|
+
# Perform validation for sort codes with MOD10
|
4
|
+
class StandardModulus < BaseValidator
|
5
|
+
def modulus
|
6
|
+
fail NotImplementedError
|
7
|
+
end
|
8
|
+
|
9
|
+
def valid?
|
10
|
+
test_string = sort_code + account_number
|
11
|
+
|
12
|
+
test_digits = test_string.split(//).map(&:to_i)
|
13
|
+
|
14
|
+
total = applying_exceptions(test_digits) do
|
15
|
+
NUMBER_INDEX.each_pair.reduce(0) do |t, pair|
|
16
|
+
weight, index = pair
|
17
|
+
|
18
|
+
t + modulus_weight.send(weight) * test_digits[index]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
if exception.override_test?
|
23
|
+
return exception.test(modulus, total, test_digits, :standard_modulus)
|
24
|
+
end
|
25
|
+
|
26
|
+
total % modulus == 0
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'uk_account_validator/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'uk_account_validator_auctionet'
|
8
|
+
spec.version = UkAccountValidator::VERSION
|
9
|
+
spec.authors = ['Hayden Ball', 'Henrik Nyh']
|
10
|
+
spec.email = ['hayden@haydenball.me.uk', 'henrik.nyh@auctionet.com']
|
11
|
+
spec.summary = 'Validate UK Account Numbers and Sort Codes'
|
12
|
+
spec.description = spec.summary
|
13
|
+
spec.homepage = 'https://github.com/barsoom/uk_account_validator'
|
14
|
+
spec.license = '2 Clause BSD'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(/^bin\//) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(/^(test|spec|features)\//)
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.required_ruby_version = '>= 2.0.0'
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: uk_account_validator_auctionet
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.8
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Hayden Ball
|
8
|
+
- Henrik Nyh
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2018-10-18 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Validate UK Account Numbers and Sort Codes
|
15
|
+
email:
|
16
|
+
- hayden@haydenball.me.uk
|
17
|
+
- henrik.nyh@auctionet.com
|
18
|
+
executables: []
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- ".gitignore"
|
23
|
+
- ".rubocop.yml"
|
24
|
+
- ".travis.yml"
|
25
|
+
- Gemfile
|
26
|
+
- LICENSE.txt
|
27
|
+
- README.md
|
28
|
+
- Rakefile
|
29
|
+
- data/scsubtab.txt
|
30
|
+
- data/valacdos.txt
|
31
|
+
- features/allow_hyphens_in_sort_codes.feature
|
32
|
+
- features/exceptions.feature
|
33
|
+
- features/invalid_formats.feature
|
34
|
+
- features/modulus10.feature
|
35
|
+
- features/modulus11.feature
|
36
|
+
- features/modulus_weight.feature
|
37
|
+
- features/modulus_weights_table.feature
|
38
|
+
- features/step_definitions/basics.rb
|
39
|
+
- features/step_definitions/modulus_weight.rb
|
40
|
+
- features/step_definitions/modulus_weights_table.rb
|
41
|
+
- features/support/env.rb
|
42
|
+
- features/two_modulus_check.feature
|
43
|
+
- lib/uk_account_validator.rb
|
44
|
+
- lib/uk_account_validator/backports/array_bsearch_index.rb
|
45
|
+
- lib/uk_account_validator/exceptions/base_exception.rb
|
46
|
+
- lib/uk_account_validator/exceptions/exception_1.rb
|
47
|
+
- lib/uk_account_validator/exceptions/exception_10.rb
|
48
|
+
- lib/uk_account_validator/exceptions/exception_12.rb
|
49
|
+
- lib/uk_account_validator/exceptions/exception_14.rb
|
50
|
+
- lib/uk_account_validator/exceptions/exception_2_9.rb
|
51
|
+
- lib/uk_account_validator/exceptions/exception_3.rb
|
52
|
+
- lib/uk_account_validator/exceptions/exception_4.rb
|
53
|
+
- lib/uk_account_validator/exceptions/exception_5.rb
|
54
|
+
- lib/uk_account_validator/exceptions/exception_6.rb
|
55
|
+
- lib/uk_account_validator/exceptions/exception_7.rb
|
56
|
+
- lib/uk_account_validator/exceptions/exception_8.rb
|
57
|
+
- lib/uk_account_validator/modulus_weight.rb
|
58
|
+
- lib/uk_account_validator/modulus_weights_table.rb
|
59
|
+
- lib/uk_account_validator/number_indices.rb
|
60
|
+
- lib/uk_account_validator/validator.rb
|
61
|
+
- lib/uk_account_validator/validators/base_validator.rb
|
62
|
+
- lib/uk_account_validator/validators/double_alternate.rb
|
63
|
+
- lib/uk_account_validator/validators/modulus10.rb
|
64
|
+
- lib/uk_account_validator/validators/modulus11.rb
|
65
|
+
- lib/uk_account_validator/validators/standard_modulus.rb
|
66
|
+
- lib/uk_account_validator/version.rb
|
67
|
+
- uk_account_validator.gemspec
|
68
|
+
homepage: https://github.com/barsoom/uk_account_validator
|
69
|
+
licenses:
|
70
|
+
- 2 Clause BSD
|
71
|
+
metadata: {}
|
72
|
+
post_install_message:
|
73
|
+
rdoc_options: []
|
74
|
+
require_paths:
|
75
|
+
- lib
|
76
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: 2.0.0
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
requirements: []
|
87
|
+
rubyforge_project:
|
88
|
+
rubygems_version: 2.6.11
|
89
|
+
signing_key:
|
90
|
+
specification_version: 4
|
91
|
+
summary: Validate UK Account Numbers and Sort Codes
|
92
|
+
test_files:
|
93
|
+
- features/allow_hyphens_in_sort_codes.feature
|
94
|
+
- features/exceptions.feature
|
95
|
+
- features/invalid_formats.feature
|
96
|
+
- features/modulus10.feature
|
97
|
+
- features/modulus11.feature
|
98
|
+
- features/modulus_weight.feature
|
99
|
+
- features/modulus_weights_table.feature
|
100
|
+
- features/step_definitions/basics.rb
|
101
|
+
- features/step_definitions/modulus_weight.rb
|
102
|
+
- features/step_definitions/modulus_weights_table.rb
|
103
|
+
- features/support/env.rb
|
104
|
+
- features/two_modulus_check.feature
|