banktools-gb 0.5.0 → 0.13.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 +5 -5
- data/.github/workflows/ci.yml +26 -0
- data/.rubocop.yml +5 -0
- data/Gemfile +5 -0
- data/README.md +27 -23
- data/banktools-gb.gemspec +8 -8
- data/lib/banktools-gb/account.rb +43 -0
- data/lib/banktools-gb/errors.rb +7 -7
- data/lib/banktools-gb/sort_code.rb +38 -0
- data/lib/banktools-gb/version.rb +3 -3
- data/lib/banktools-gb.rb +2 -4
- metadata +18 -30
- data/.travis.yml +0 -6
- data/lib/banktools-gb/account_number_with_sort_code.rb +0 -65
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8f241c891a2df2eb6956201979b16081156a886ca681486b1eeb66756275ba31
|
4
|
+
data.tar.gz: '0975475a825a66dc1b6653a17dd9fa8baa55dd9eac1866c8e140d31590caf62a'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1823f38ba139459d6dfde4d1732f14d9e7df62c77b99bede06de3d910a3df70a8df47c2f0e76bba5ea28f93061894499cc6edff816548d9eff0f323774895607
|
7
|
+
data.tar.gz: b89460ed009cd2c14d3c41ab527a183c30bc2a60413216ebce426d7e4d573ef0d7ae624ad1b0e68748faf331819e4e27fc28b518e276e63f09fbf8db430e6a27
|
@@ -0,0 +1,26 @@
|
|
1
|
+
name: Ruby CI
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [ master ]
|
6
|
+
pull_request:
|
7
|
+
branches: [ master ]
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
test:
|
11
|
+
|
12
|
+
runs-on: ubuntu-latest
|
13
|
+
|
14
|
+
strategy:
|
15
|
+
matrix:
|
16
|
+
ruby-version: ["3.0", "2.7", "2.6", "2.5"]
|
17
|
+
|
18
|
+
steps:
|
19
|
+
- uses: actions/checkout@v2
|
20
|
+
- name: Set up Ruby ${{ matrix.ruby-version }}
|
21
|
+
uses: ruby/setup-ruby@ae9cb3b565e36682a2c6045e4f664388da4c73aa
|
22
|
+
with:
|
23
|
+
ruby-version: ${{ matrix.ruby-version }}
|
24
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
25
|
+
- name: Run tests
|
26
|
+
run: bundle exec rake
|
data/.rubocop.yml
ADDED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,35 +1,44 @@
|
|
1
1
|
# United Kingdom bank tools
|
2
2
|
|
3
|
-
[](https://github.com/barsoom/banktools-gb/actions/workflows/ci.yml)
|
4
4
|
|
5
|
-
Ruby gem to validate United Kingdom bank account numbers.
|
5
|
+
Ruby gem to validate United Kingdom sort codes and bank account numbers.
|
6
|
+
|
7
|
+
When in doubt, this library aims to err on the side of allowing too much.
|
6
8
|
|
7
9
|
If we got anything wrong, please file an issue or contribute a fix yourself.
|
8
10
|
|
9
11
|
## Usage
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
-
|
13
|
+
```ruby
|
14
|
+
# Sort code
|
15
|
+
|
16
|
+
sort_code = BankTools::GB::SortCode.new("60-16-13")
|
17
|
+
sort_code.valid? # => true
|
18
|
+
sort_code.errors # => []
|
19
|
+
|
20
|
+
bad_sort_code = BankTools::GB::SortCode.new("1X")
|
21
|
+
bad_sort_code.valid? # => false
|
22
|
+
bad_sort_code.errors # => [ :too_short, :invalid_characters ]
|
14
23
|
|
15
|
-
|
16
|
-
bad_account.valid? # => false
|
17
|
-
bad_account.errors # => [:account_number_is_too_short]
|
24
|
+
# Account
|
18
25
|
|
19
|
-
|
26
|
+
account = BankTools::GB::Account.new("31926819")
|
27
|
+
account.valid? # => true
|
28
|
+
account.errors # => []
|
20
29
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
BankTools::GB::Errors::SORT_CODE_WITH_INVALID_CHARACTERS # => :sort_code_with_invalid_characters
|
26
|
-
BankTools::GB::Errors::ACCOUNT_NUMBER_DOES_NOT_MATCH_SORT_CODE # => :account_number_does_not_match_sort_code
|
30
|
+
bad_account = BankTools::GB::Account.new("1")
|
31
|
+
bad_account.valid? # => false
|
32
|
+
bad_account.errors # => [ :too_short ]
|
33
|
+
```
|
27
34
|
|
28
35
|
## Installation
|
29
36
|
|
30
37
|
Add this line to your application's Gemfile:
|
31
38
|
|
32
|
-
|
39
|
+
```ruby
|
40
|
+
gem "banktools-gb"
|
41
|
+
```
|
33
42
|
|
34
43
|
And then execute:
|
35
44
|
|
@@ -46,18 +55,13 @@ Or install it yourself as:
|
|
46
55
|
|
47
56
|
## Also see
|
48
57
|
|
49
|
-
* [BankTools
|
50
|
-
* [
|
51
|
-
* [BankTools::DK (German)](https://github.com/barsoom/banktools-dk)
|
58
|
+
* [Our other BankTools](https://github.com/barsoom?q=banktools)
|
59
|
+
* [BanklineCsvImportFile](https://github.com/barsoom/bankline_csv_import_file)
|
52
60
|
|
53
61
|
## Credits
|
54
62
|
|
55
63
|
* [Hayden Ball](https://github.com/ball-hayden) for creating [UkAccountValidator](https://github.com/ball-hayden/uk_account_validator) that we base this gem on.
|
56
64
|
|
57
|
-
## Contributing
|
58
|
-
|
59
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/banktools-gb.
|
60
|
-
|
61
65
|
## License
|
62
66
|
|
63
67
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/banktools-gb.gemspec
CHANGED
@@ -5,9 +5,9 @@ require "banktools-gb/version"
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "banktools-gb"
|
8
|
-
spec.version =
|
9
|
-
spec.authors = ["Tomas Skogberg"]
|
10
|
-
spec.email = ["tomas@auctionet.com"]
|
8
|
+
spec.version = BankTools::GB::VERSION
|
9
|
+
spec.authors = [ "Tomas Skogberg" ]
|
10
|
+
spec.email = [ "tomas@auctionet.com" ]
|
11
11
|
|
12
12
|
spec.summary = %q{Validate and normalise United Kingdom bank account numbers.}
|
13
13
|
spec.homepage = "https://github.com/barsoom/banktools-gb"
|
@@ -16,12 +16,12 @@ Gem::Specification.new do |spec|
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
17
|
spec.bindir = "exe"
|
18
18
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
-
spec.require_paths = ["lib"]
|
19
|
+
spec.require_paths = [ "lib" ]
|
20
|
+
spec.metadata = { "rubygems_mfa_required" => "true" }
|
20
21
|
|
21
|
-
spec.add_dependency "
|
22
|
-
spec.add_dependency "attr_extras", "~> 5"
|
22
|
+
spec.add_dependency "attr_extras"
|
23
23
|
|
24
|
-
spec.add_development_dependency "bundler", "
|
25
|
-
spec.add_development_dependency "rake", "
|
24
|
+
spec.add_development_dependency "bundler", ">= 1"
|
25
|
+
spec.add_development_dependency "rake", ">= 12.3.3"
|
26
26
|
spec.add_development_dependency "rspec", "~> 3"
|
27
27
|
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require "attr_extras/explicit"
|
2
|
+
require "banktools-gb/errors"
|
3
|
+
|
4
|
+
module BankTools
|
5
|
+
module GB
|
6
|
+
class Account
|
7
|
+
extend AttrExtras.mixin
|
8
|
+
|
9
|
+
# Officially, bank accounts in the UK can be between 6 and 10 digits, but
|
10
|
+
# the standard is 8, and any system that receives them will require them to
|
11
|
+
# be zero-padded. Customers should be used to prepend zeroes, and it should not be an issue.
|
12
|
+
# If this becomes an issue, lets consider handling auto-zeropadding, but it is both
|
13
|
+
# less technical issues and easier to give feedback to the user if we enforce the 8 digit length rule.
|
14
|
+
LENGTH = 8
|
15
|
+
|
16
|
+
pattr_initialize :original_value
|
17
|
+
|
18
|
+
def valid?
|
19
|
+
errors.none?
|
20
|
+
end
|
21
|
+
|
22
|
+
def errors
|
23
|
+
errors = []
|
24
|
+
|
25
|
+
errors << Errors::ACCOUNT_TOO_SHORT if compacted_value.length < LENGTH
|
26
|
+
errors << Errors::ACCOUNT_TOO_LONG if compacted_value.length > LENGTH
|
27
|
+
errors << Errors::ACCOUNT_INVALID_CHARACTERS if any_non_digits?
|
28
|
+
|
29
|
+
errors
|
30
|
+
end
|
31
|
+
|
32
|
+
def compacted_value
|
33
|
+
original_value.to_s.gsub(/[\s-]/, "")
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def any_non_digits?
|
39
|
+
compacted_value.match(/\D/)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/lib/banktools-gb/errors.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
module
|
1
|
+
module BankTools
|
2
2
|
module GB
|
3
3
|
module Errors
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
4
|
+
ACCOUNT_TOO_SHORT = :account_too_short
|
5
|
+
ACCOUNT_TOO_LONG = :account_too_long
|
6
|
+
SORT_CODE_TOO_SHORT = :sort_code_too_short
|
7
|
+
SORT_CODE_TOO_LONG = :sort_code_too_long
|
8
|
+
ACCOUNT_INVALID_CHARACTERS = :account_invalid_characters
|
9
|
+
SORT_CODE_INVALID_CHARACTERS = :sort_code_invalid_characters
|
10
10
|
end
|
11
11
|
end
|
12
12
|
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require "attr_extras/explicit"
|
2
|
+
require "banktools-gb/errors"
|
3
|
+
|
4
|
+
module BankTools
|
5
|
+
module GB
|
6
|
+
class SortCode
|
7
|
+
extend AttrExtras.mixin
|
8
|
+
|
9
|
+
LENGTH = 6
|
10
|
+
|
11
|
+
pattr_initialize :original_value
|
12
|
+
|
13
|
+
def valid?
|
14
|
+
errors.none?
|
15
|
+
end
|
16
|
+
|
17
|
+
def errors
|
18
|
+
errors = []
|
19
|
+
|
20
|
+
errors << Errors::SORT_CODE_TOO_SHORT if compacted_value.length < LENGTH
|
21
|
+
errors << Errors::SORT_CODE_TOO_LONG if compacted_value.length > LENGTH
|
22
|
+
errors << Errors::SORT_CODE_INVALID_CHARACTERS if any_non_digits?
|
23
|
+
|
24
|
+
errors
|
25
|
+
end
|
26
|
+
|
27
|
+
def compacted_value
|
28
|
+
original_value.to_s.gsub(/[\s-]/, "")
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def any_non_digits?
|
34
|
+
compacted_value.match(/\D/)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/banktools-gb/version.rb
CHANGED
data/lib/banktools-gb.rb
CHANGED
metadata
CHANGED
@@ -1,71 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: banktools-gb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.13.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tomas Skogberg
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-11-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: attr_extras
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: attr_extras
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '5'
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '5'
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: bundler
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
44
30
|
requirements:
|
45
|
-
- - "
|
31
|
+
- - ">="
|
46
32
|
- !ruby/object:Gem::Version
|
47
33
|
version: '1'
|
48
34
|
type: :development
|
49
35
|
prerelease: false
|
50
36
|
version_requirements: !ruby/object:Gem::Requirement
|
51
37
|
requirements:
|
52
|
-
- - "
|
38
|
+
- - ">="
|
53
39
|
- !ruby/object:Gem::Version
|
54
40
|
version: '1'
|
55
41
|
- !ruby/object:Gem::Dependency
|
56
42
|
name: rake
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|
58
44
|
requirements:
|
59
|
-
- - "
|
45
|
+
- - ">="
|
60
46
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
47
|
+
version: 12.3.3
|
62
48
|
type: :development
|
63
49
|
prerelease: false
|
64
50
|
version_requirements: !ruby/object:Gem::Requirement
|
65
51
|
requirements:
|
66
|
-
- - "
|
52
|
+
- - ">="
|
67
53
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
54
|
+
version: 12.3.3
|
69
55
|
- !ruby/object:Gem::Dependency
|
70
56
|
name: rspec
|
71
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -87,9 +73,10 @@ executables: []
|
|
87
73
|
extensions: []
|
88
74
|
extra_rdoc_files: []
|
89
75
|
files:
|
76
|
+
- ".github/workflows/ci.yml"
|
90
77
|
- ".gitignore"
|
91
78
|
- ".rspec"
|
92
|
-
- ".
|
79
|
+
- ".rubocop.yml"
|
93
80
|
- Gemfile
|
94
81
|
- LICENSE.txt
|
95
82
|
- README.md
|
@@ -98,13 +85,15 @@ files:
|
|
98
85
|
- bin/console
|
99
86
|
- bin/setup
|
100
87
|
- lib/banktools-gb.rb
|
101
|
-
- lib/banktools-gb/
|
88
|
+
- lib/banktools-gb/account.rb
|
102
89
|
- lib/banktools-gb/errors.rb
|
90
|
+
- lib/banktools-gb/sort_code.rb
|
103
91
|
- lib/banktools-gb/version.rb
|
104
92
|
homepage: https://github.com/barsoom/banktools-gb
|
105
93
|
licenses:
|
106
94
|
- MIT
|
107
|
-
metadata:
|
95
|
+
metadata:
|
96
|
+
rubygems_mfa_required: 'true'
|
108
97
|
post_install_message:
|
109
98
|
rdoc_options: []
|
110
99
|
require_paths:
|
@@ -120,8 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
120
109
|
- !ruby/object:Gem::Version
|
121
110
|
version: '0'
|
122
111
|
requirements: []
|
123
|
-
|
124
|
-
rubygems_version: 2.5.1
|
112
|
+
rubygems_version: 3.2.28
|
125
113
|
signing_key:
|
126
114
|
specification_version: 4
|
127
115
|
summary: Validate and normalise United Kingdom bank account numbers.
|
data/.travis.yml
DELETED
@@ -1,65 +0,0 @@
|
|
1
|
-
require "attr_extras/explicit"
|
2
|
-
require "banktools-gb/errors"
|
3
|
-
|
4
|
-
module BankTools
|
5
|
-
module GB
|
6
|
-
class AccountNumberWithSortCode
|
7
|
-
extend AttrExtras.mixin
|
8
|
-
|
9
|
-
ACCOUNT_NUMBER_MIN_LENGTH = 6
|
10
|
-
ACCOUNT_NUMBER_MAX_LENGTH = 10
|
11
|
-
SORT_CODE_LENGTH = 6
|
12
|
-
|
13
|
-
pattr_initialize [ :account_number, :sort_code ]
|
14
|
-
|
15
|
-
def valid?
|
16
|
-
errors.none?
|
17
|
-
end
|
18
|
-
|
19
|
-
def errors
|
20
|
-
errors = []
|
21
|
-
errors << :account_number_is_too_short if account_number_is_too_short?
|
22
|
-
errors << :account_number_is_too_long if account_number_is_too_long?
|
23
|
-
errors << :sort_code_with_wrong_length if sort_code_with_wrong_length?
|
24
|
-
errors << :sort_code_with_invalid_characters if any_non_digits?(compact_sort_code)
|
25
|
-
errors << :account_number_with_invalid_characters if any_non_digits?(compact_account_number)
|
26
|
-
errors << :account_number_does_not_match_sort_code unless valid_account_number_with_sort_code?
|
27
|
-
errors
|
28
|
-
end
|
29
|
-
|
30
|
-
private
|
31
|
-
|
32
|
-
def valid_account_number_with_sort_code?
|
33
|
-
UkAccountValidator::Validator.new(compact_account_number, compact_sort_code).valid?
|
34
|
-
end
|
35
|
-
|
36
|
-
def sort_code_with_wrong_length?
|
37
|
-
compact_sort_code.length != SORT_CODE_LENGTH
|
38
|
-
end
|
39
|
-
|
40
|
-
def account_number_is_too_short?
|
41
|
-
compact_account_number.length < ACCOUNT_NUMBER_MIN_LENGTH
|
42
|
-
end
|
43
|
-
|
44
|
-
def account_number_is_too_long?
|
45
|
-
compact_account_number.length > ACCOUNT_NUMBER_MAX_LENGTH
|
46
|
-
end
|
47
|
-
|
48
|
-
def any_non_digits?(number)
|
49
|
-
number.match(/\D/)
|
50
|
-
end
|
51
|
-
|
52
|
-
def compact_sort_code
|
53
|
-
compact(sort_code)
|
54
|
-
end
|
55
|
-
|
56
|
-
def compact_account_number
|
57
|
-
compact(account_number)
|
58
|
-
end
|
59
|
-
|
60
|
-
def compact(number)
|
61
|
-
number.gsub(/[\s-]/, "")
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|