uk_account_validator 0.0.2 → 0.0.3
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 +4 -4
- data/README.md +4 -0
- data/features/allow_hyphens_in_sort_codes.feature +9 -0
- data/features/invalid_formats.feature +33 -0
- data/features/step_definitions/basics.rb +2 -2
- data/lib/uk_account_validator/validator.rb +18 -1
- data/lib/uk_account_validator/version.rb +1 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ebcd385fc8ba4ecc1703657a83b9b0eb45b30b51
|
4
|
+
data.tar.gz: 5114241aa01ffbfcc0ce676084f133b0c134dea4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e95c9284cbc1423203ea396c5cba5d97ff46c104458ec031c63a3e6f60433c124d6e43905d7d0e54e5d04f4d98f410f5d05b7b8d16087e6e2288f44bde26c7cc
|
7
|
+
data.tar.gz: 9cdb8baca1a7cd094f963331fae6cd72a2f59616b693c398206a65b326b9799e4d18007dc9e2a5fc90cadebb225989111c7476ea2ba19df90fb167e3b2a8f5d9
|
data/README.md
CHANGED
@@ -7,6 +7,10 @@ This gem validates uk account numbers against their sort codes in accordance wit
|
|
7
7
|
|
8
8
|
http://www.vocalink.com/media/700427/vocalink_-_validating_account_numbers_v3.20.pdf
|
9
9
|
|
10
|
+
Note that this gem ensures the sort code and account number are valid, not that they exist.
|
11
|
+
|
12
|
+
NB the resource text files valacdos.txt and scsubtab.txt are produced and released by VocaLink.
|
13
|
+
|
10
14
|
Requires Ruby > 2.0.0
|
11
15
|
|
12
16
|
Usage
|
@@ -0,0 +1,33 @@
|
|
1
|
+
Feature: Account number and sort code must be in recognised format
|
2
|
+
Background:
|
3
|
+
Given I create a new checker
|
4
|
+
|
5
|
+
Scenario: Account number contains letters
|
6
|
+
Given I have a sort code 089999
|
7
|
+
And I have an account number abcdefgh
|
8
|
+
|
9
|
+
Then the combination is invalid
|
10
|
+
|
11
|
+
Scenario: Account number must be at least 6 digits
|
12
|
+
Given I have a sort code 089999
|
13
|
+
And I have an account number 66374
|
14
|
+
|
15
|
+
Then the combination is invalid
|
16
|
+
|
17
|
+
Scenario: Account number may not be more than 10 digits
|
18
|
+
Given I have a sort code 089999
|
19
|
+
And I have an account number 66374958663
|
20
|
+
|
21
|
+
Then the combination is invalid
|
22
|
+
|
23
|
+
Scenario: The sort code may not be less than 6 digits
|
24
|
+
Given I have a sort code 08999
|
25
|
+
And I have an account number 66374958
|
26
|
+
|
27
|
+
Then the combination is invalid
|
28
|
+
|
29
|
+
Scenario: The sort code may not be more than 6 digits
|
30
|
+
Given I have a sort code 0899999
|
31
|
+
And I have an account number 66374958
|
32
|
+
|
33
|
+
Then the combination is invalid
|
@@ -2,11 +2,11 @@ Given(/^I create a new checker$/) do
|
|
2
2
|
@checker = UkAccountValidator::Validator.new
|
3
3
|
end
|
4
4
|
|
5
|
-
Given(/^I have a sort code (\
|
5
|
+
Given(/^I have a sort code (\S+)$/) do |sort_code|
|
6
6
|
@checker.sort_code = sort_code
|
7
7
|
end
|
8
8
|
|
9
|
-
Given(/^I have an account number (\
|
9
|
+
Given(/^I have an account number (\S+)$/) do |acc_number|
|
10
10
|
@checker.account_number = acc_number
|
11
11
|
end
|
12
12
|
|
@@ -1,12 +1,18 @@
|
|
1
1
|
module UkAccountValidator
|
2
2
|
class Validator
|
3
|
-
|
3
|
+
|
4
|
+
attr_writer :sort_code
|
5
|
+
attr_accessor :account_number
|
4
6
|
|
5
7
|
def initialize(account_number = nil, sort_code = nil)
|
6
8
|
@account_number = account_number
|
7
9
|
@sort_code = sort_code
|
8
10
|
end
|
9
11
|
|
12
|
+
def sort_code
|
13
|
+
@sort_code.gsub('-', '')
|
14
|
+
end
|
15
|
+
|
10
16
|
def modulus_weights
|
11
17
|
@modulus_weights ||= UkAccountValidator.modulus_weights_table.find(sort_code)
|
12
18
|
end
|
@@ -25,6 +31,8 @@ module UkAccountValidator
|
|
25
31
|
end
|
26
32
|
|
27
33
|
def valid?
|
34
|
+
return false unless valid_format?
|
35
|
+
|
28
36
|
exceptions = modulus_weights.map(&:exception)
|
29
37
|
exception_class = self.exception_class(exceptions)
|
30
38
|
|
@@ -43,6 +51,15 @@ module UkAccountValidator
|
|
43
51
|
results.all?
|
44
52
|
end
|
45
53
|
|
54
|
+
def valid_format?
|
55
|
+
return false if account_number =~ /\D/
|
56
|
+
return false if account_number.length < 6
|
57
|
+
return false if account_number.length > 10
|
58
|
+
return false if sort_code.length != 6
|
59
|
+
|
60
|
+
return true
|
61
|
+
end
|
62
|
+
|
46
63
|
def exception_class(exception_strings)
|
47
64
|
case
|
48
65
|
when exception_strings.include?('1')
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: uk_account_validator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hayden Ball
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-17 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Validate UK Account Numbers and Sort Codes
|
14
14
|
email:
|
@@ -26,7 +26,9 @@ files:
|
|
26
26
|
- Rakefile
|
27
27
|
- data/scsubtab.txt
|
28
28
|
- data/valacdos.txt
|
29
|
+
- features/allow_hyphens_in_sort_codes.feature
|
29
30
|
- features/exceptions.feature
|
31
|
+
- features/invalid_formats.feature
|
30
32
|
- features/modulus10.feature
|
31
33
|
- features/modulus11.feature
|
32
34
|
- features/modulus_weight.feature
|
@@ -85,7 +87,9 @@ signing_key:
|
|
85
87
|
specification_version: 4
|
86
88
|
summary: Validate UK Account Numbers and Sort Codes
|
87
89
|
test_files:
|
90
|
+
- features/allow_hyphens_in_sort_codes.feature
|
88
91
|
- features/exceptions.feature
|
92
|
+
- features/invalid_formats.feature
|
89
93
|
- features/modulus10.feature
|
90
94
|
- features/modulus11.feature
|
91
95
|
- features/modulus_weight.feature
|