uk_account_validator 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/.rubocop.yml +11 -0
- data/.travis.yml +13 -0
- data/Gemfile +14 -0
- data/LICENSE.txt +23 -0
- data/README.md +56 -0
- data/Rakefile +2 -0
- data/data/scsubtab.txt +21 -0
- data/data/valacdos.txt +987 -0
- data/features/exceptions.feature +49 -0
- data/features/modulus10.feature +18 -0
- data/features/modulus11.feature +15 -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 +41 -0
- data/lib/uk_account_validator/modulus_weight.rb +35 -0
- data/lib/uk_account_validator/modulus_weights_table.rb +31 -0
- data/lib/uk_account_validator/validator.rb +60 -0
- data/lib/uk_account_validator/validators/base_validator.rb +154 -0
- data/lib/uk_account_validator/validators/double_alternate.rb +38 -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 +33 -0
- data/lib/uk_account_validator/version.rb +3 -0
- data/uk_account_validator.gemspec +22 -0
- metadata +84 -0
@@ -0,0 +1,38 @@
|
|
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
|
+
case @modulus_weight.exception
|
28
|
+
when '4'
|
29
|
+
return apply_exception_4(total, test_digits)
|
30
|
+
when '5'
|
31
|
+
return apply_exception_5(total, test_digits, :h)
|
32
|
+
end
|
33
|
+
|
34
|
+
total % modulus == 0
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,33 @@
|
|
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
|
+
case @modulus_weight.exception
|
23
|
+
when '4'
|
24
|
+
return apply_exception_4(total, test_digits)
|
25
|
+
when '5'
|
26
|
+
return apply_exception_5(total, test_digits, :g)
|
27
|
+
end
|
28
|
+
|
29
|
+
total % modulus == 0
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
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'
|
8
|
+
spec.version = UkAccountValidator::VERSION
|
9
|
+
spec.authors = ['Hayden Ball']
|
10
|
+
spec.email = ['hayden@haydenball.me.uk']
|
11
|
+
spec.summary = 'Validate UK Account Numbers and Sort Codes'
|
12
|
+
spec.description = spec.summary
|
13
|
+
spec.homepage = ''
|
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,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: uk_account_validator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Hayden Ball
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-05-16 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Validate UK Account Numbers and Sort Codes
|
14
|
+
email:
|
15
|
+
- hayden@haydenball.me.uk
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- ".gitignore"
|
21
|
+
- ".rubocop.yml"
|
22
|
+
- ".travis.yml"
|
23
|
+
- Gemfile
|
24
|
+
- LICENSE.txt
|
25
|
+
- README.md
|
26
|
+
- Rakefile
|
27
|
+
- data/scsubtab.txt
|
28
|
+
- data/valacdos.txt
|
29
|
+
- features/exceptions.feature
|
30
|
+
- features/modulus10.feature
|
31
|
+
- features/modulus11.feature
|
32
|
+
- features/modulus_weight.feature
|
33
|
+
- features/modulus_weights_table.feature
|
34
|
+
- features/step_definitions/basics.rb
|
35
|
+
- features/step_definitions/modulus_weight.rb
|
36
|
+
- features/step_definitions/modulus_weights_table.rb
|
37
|
+
- features/support/env.rb
|
38
|
+
- features/two_modulus_check.feature
|
39
|
+
- lib/uk_account_validator.rb
|
40
|
+
- lib/uk_account_validator/modulus_weight.rb
|
41
|
+
- lib/uk_account_validator/modulus_weights_table.rb
|
42
|
+
- lib/uk_account_validator/validator.rb
|
43
|
+
- lib/uk_account_validator/validators/base_validator.rb
|
44
|
+
- lib/uk_account_validator/validators/double_alternate.rb
|
45
|
+
- lib/uk_account_validator/validators/modulus10.rb
|
46
|
+
- lib/uk_account_validator/validators/modulus11.rb
|
47
|
+
- lib/uk_account_validator/validators/standard_modulus.rb
|
48
|
+
- lib/uk_account_validator/version.rb
|
49
|
+
- uk_account_validator.gemspec
|
50
|
+
homepage: ''
|
51
|
+
licenses:
|
52
|
+
- 2 Clause BSD
|
53
|
+
metadata: {}
|
54
|
+
post_install_message:
|
55
|
+
rdoc_options: []
|
56
|
+
require_paths:
|
57
|
+
- lib
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 2.0.0
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
requirements: []
|
69
|
+
rubyforge_project:
|
70
|
+
rubygems_version: 2.4.5
|
71
|
+
signing_key:
|
72
|
+
specification_version: 4
|
73
|
+
summary: Validate UK Account Numbers and Sort Codes
|
74
|
+
test_files:
|
75
|
+
- features/exceptions.feature
|
76
|
+
- features/modulus10.feature
|
77
|
+
- features/modulus11.feature
|
78
|
+
- features/modulus_weight.feature
|
79
|
+
- features/modulus_weights_table.feature
|
80
|
+
- features/step_definitions/basics.rb
|
81
|
+
- features/step_definitions/modulus_weight.rb
|
82
|
+
- features/step_definitions/modulus_weights_table.rb
|
83
|
+
- features/support/env.rb
|
84
|
+
- features/two_modulus_check.feature
|