banktools-gb 0.5.0 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c0f3e7f61bc8d6f56034536be0c064e6cf1f7d18
4
- data.tar.gz: bb3a03b154524de3daed3de0d75513236b4541c8
3
+ metadata.gz: ffdb9dce789b6c5c38ef0e3178ee9a3e80172267
4
+ data.tar.gz: 2753c4af90e0ebb2b7bdd4ac45dc67648139729b
5
5
  SHA512:
6
- metadata.gz: 9a57461e8877d93410799c501e87d06cd995d9c92519f29731d3fdcef79c3450d43a0b23f2f4a0d8a149d5d7f9248ee711b15f7731de935855d51372abbf470a
7
- data.tar.gz: f7e80fe6f3758b54ab86cd6f452172537fa0f684517313cce0b619a8b84b40e68824b1a201a6295695c8f7a46487dc14e5a320e5d5ac4ace2f909f4759b9e160
6
+ metadata.gz: e493caa282cadc173b55f63ca09eda5ac1ffb248b9ff882e355adb347e1978561321eaa25ec4c20895baa869816b9962bce1cf84ec6371cb23cb776b3c171987
7
+ data.tar.gz: 3f77553a66f5234082d2b2b150ebb3e4876939b4778ec1c699d26f2256d70151c8a833220342296f004df5d1398085aab77cf7ba1747b7162183b3d33a68b57e
data/README.md CHANGED
@@ -2,28 +2,45 @@
2
2
 
3
3
  [![Build Status](https://travis-ci.org/barsoom/banktools-gb.svg?branch=master)](https://travis-ci.org/barsoom/banktools-gb)
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
- account = BankTools::GB::AccountNumberWithSortCode.new(account_number: "31926819", sort_code: "60-16-13")
13
+ # Sort code
14
+
15
+ sort_code = BankTools::GB::SortCode.new("60-16-13")
16
+ sort_code.valid? # => true
17
+ sort_code.errors # => []
18
+
19
+ bad_sort_code = BankTools::GB::SortCode.new("1X")
20
+ bad_sort_code.valid? # => false
21
+ bad_sort_code.errors # => [ :too_short, :invalid_characters ]
22
+
23
+ # Account
24
+
25
+ account = BankTools::GB::Account.new("31926819")
12
26
  account.valid? # => true
13
27
  account.errors # => []
14
28
 
15
- bad_account = BankTools::GB::AccountNumberWithSortCode.new(account_number: "1", sort_code: "")
29
+ bad_account = BankTools::GB::Account.new("1")
16
30
  bad_account.valid? # => false
17
- bad_account.errors # => [:account_number_is_too_short]
31
+ bad_account.errors # => [ :too_short ]
18
32
 
19
- # Error codes
20
33
 
21
- BankTools::GB::Errors::ACCOUNT_NUMBER_IS_TOO_SHORT # => :account_number_is_too_short
22
- BankTools::GB::Errors::ACCOUNT_NUMBER_IS_TOO_LONG # => :account_number_is_too_long
23
- BankTools::GB::Errors::SORT_CODE_WITH_WRONG_LENGTH # => :sort_code_with_wrong_length
24
- BankTools::GB::Errors::ACCOUNT_NUMBER_WITH_INVALID_CHARACTERS # => :account_number_with_invalid_characters
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
34
+ # Account and sort code (checksum check and others)
35
+ # This relies on [our fork of the uk_account_validator gem](https://github.com/barsoom/uk_account_validator). If that gem is out of date, the checksum check may be also.
36
+
37
+ account_and_sort_code = BankTools::GB::AccountNumberAndSortCode.new(account_number_original_value: 14248387, sort_code_original_value: 405161).valid?
38
+ account_and_sort_code.valid? # => true
39
+ account_and_sort_code.errors # => []
40
+
41
+ account_and_sort_code = BankTools::GB::AccountNumberAndSortCode.new(account_number_original_value: 14248387, sort_code_original_value: "xx")
42
+ account_and_sort_code.valid? # => false
43
+ account_and_sort_code.errors # => [:sort_code_too_short, :sort_code_invalid_characters, :bad_checksum]
27
44
 
28
45
  ## Installation
29
46
 
@@ -46,18 +63,13 @@ Or install it yourself as:
46
63
 
47
64
  ## Also see
48
65
 
49
- * [BankTools::SE (Swedish)](https://github.com/barsoom/banktools-se)
50
- * [BankTools::DE (German)](https://github.com/barsoom/banktools-de)
51
- * [BankTools::DK (German)](https://github.com/barsoom/banktools-dk)
66
+ * [Our other BankTools](https://github.com/barsoom?q=banktools)
67
+ * [BanklineCsvImportFile](https://github.com/barsoom/bankline_csv_import_file)
52
68
 
53
69
  ## Credits
54
70
 
55
71
  * [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
72
 
57
- ## Contributing
58
-
59
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/banktools-gb.
60
-
61
73
  ## License
62
74
 
63
75
  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,7 +5,7 @@ require "banktools-gb/version"
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "banktools-gb"
8
- spec.version = Banktools::Gb::VERSION
8
+ spec.version = BankTools::GB::VERSION
9
9
  spec.authors = ["Tomas Skogberg"]
10
10
  spec.email = ["tomas@auctionet.com"]
11
11
 
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency "uk_account_validator", "~> 0"
21
+ spec.add_dependency "uk_account_validator_auctionet", "~> 0"
22
22
  spec.add_dependency "attr_extras", "~> 5"
23
23
 
24
24
  spec.add_development_dependency "bundler", "~> 1"
data/lib/banktools-gb.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require "uk_account_validator"
2
2
 
3
3
  require "banktools-gb/version"
4
- require "banktools-gb/account_number_with_sort_code"
5
- require "banktools-gb/errors"
4
+ require "banktools-gb/sort_code"
5
+ require "banktools-gb/account"
6
+ require "banktools-gb/account_number_and_sort_code"
@@ -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
@@ -0,0 +1,40 @@
1
+ require "attr_extras/explicit"
2
+ require "banktools-gb/errors"
3
+
4
+ module BankTools
5
+ module GB
6
+ class AccountNumberAndSortCode
7
+ extend AttrExtras.mixin
8
+
9
+ pattr_initialize [ :account_number_original_value, :sort_code_original_value ]
10
+
11
+ def valid?
12
+ errors.none?
13
+ end
14
+
15
+ def errors
16
+ errors = []
17
+
18
+ errors << account_number.errors
19
+ errors << sort_code.errors
20
+ errors << Errors::BAD_CHECKSUM unless valid_account_number_and_sort_code?
21
+
22
+ errors.flatten
23
+ end
24
+
25
+ private
26
+
27
+ def account_number
28
+ Account.new(account_number_original_value)
29
+ end
30
+
31
+ def sort_code
32
+ SortCode.new(sort_code_original_value)
33
+ end
34
+
35
+ def valid_account_number_and_sort_code?
36
+ UkAccountValidator::Validator.new(account_number.compacted_value, sort_code.compacted_value).valid?
37
+ end
38
+ end
39
+ end
40
+ end
@@ -1,12 +1,13 @@
1
- module Banktools
1
+ module BankTools
2
2
  module GB
3
3
  module Errors
4
- ACCOUNT_NUMBER_IS_TOO_SHORT = :account_number_is_too_short
5
- ACCOUNT_NUMBER_IS_TOO_LONG = :account_number_is_too_long
6
- SORT_CODE_WITH_WRONG_LENGTH = :sort_code_with_wrong_length
7
- SORT_CODE_WITH_INVALID_CHARACTERS = :sort_code_with_invalid_characters
8
- ACCOUNT_NUMBER_WITH_INVALID_CHARACTERS = :account_number_with_invalid_characters
9
- ACCOUNT_NUMBER_DOES_NOT_MATCH_SORT_CODE = :account_number_does_not_match_sort_code
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
+ BAD_CHECKSUM = :bad_checksum
10
11
  end
11
12
  end
12
13
  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
@@ -1,5 +1,5 @@
1
- module Banktools
2
- module Gb
3
- VERSION = "0.5.0"
1
+ module BankTools
2
+ module GB
3
+ VERSION = "0.11.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: banktools-gb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomas Skogberg
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-06-29 00:00:00.000000000 Z
11
+ date: 2018-10-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: uk_account_validator
14
+ name: uk_account_validator_auctionet
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
@@ -98,8 +98,10 @@ files:
98
98
  - bin/console
99
99
  - bin/setup
100
100
  - lib/banktools-gb.rb
101
- - lib/banktools-gb/account_number_with_sort_code.rb
101
+ - lib/banktools-gb/account.rb
102
+ - lib/banktools-gb/account_number_and_sort_code.rb
102
103
  - lib/banktools-gb/errors.rb
104
+ - lib/banktools-gb/sort_code.rb
103
105
  - lib/banktools-gb/version.rb
104
106
  homepage: https://github.com/barsoom/banktools-gb
105
107
  licenses:
@@ -121,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
121
123
  version: '0'
122
124
  requirements: []
123
125
  rubyforge_project:
124
- rubygems_version: 2.5.1
126
+ rubygems_version: 2.6.11
125
127
  signing_key:
126
128
  specification_version: 4
127
129
  summary: Validate and normalise United Kingdom bank account numbers.
@@ -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