banktools-gb 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f7844b2232f6e8f4a3abb4cda46f17b31eab9991
4
+ data.tar.gz: 45f58057f06de492845f3f67a2f94f0a2dd5c7c1
5
+ SHA512:
6
+ metadata.gz: a7f830e8b6dbe17967ba61e871a7f2c7dc5167015c77cb78f2d578c8b55e086b74845335b3cad8267b22c63ed664b2de42def0e2e99c79adfff327c402a825a9
7
+ data.tar.gz: 4808daee629b2f70ae7345ca72039228ce564ce5e8d8f6e4dbcbaf35ae204644dc900407c3f92db62ccc7a80a3c31306d0950027eb6b6c9a01ce3e73d328da59
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in banktools-gb.gemspec
4
+ gemspec
5
+
6
+ gem "uk_account_validator", github: "ball-hayden/uk_account_validator"
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Auctionet.com
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,66 @@
1
+ # United Kingdom banktools
2
+
3
+ Ruby gem to validate and normalize United Kingdom bank account numbers.
4
+
5
+ If we got anything wrong, please file an issue or contribute a fix yourself.
6
+
7
+ ## Usage
8
+
9
+ account = BankTools::GB::AccountNumberWithSortCode.new(account_number: "31926819", sort_code: "60-16-13")
10
+ account.valid? # => true
11
+ account.errors # => []
12
+
13
+ bad_account = BankTools::GB::AccountNumberWithSortCode.new(account_number: "1", sort_code: "")
14
+ bad_account.valid? # => false
15
+ bad_account.errors # => [:too_short]
16
+
17
+ # Error codes
18
+
19
+ BankTools::GB::Errors::ACCOUNT_NUMBER_TOO_SHORT # => :account_number_too_short
20
+ BankTools::GB::Errors::ACCOUNT_NUMBER_TOO_LONG # => :account_number_too_long
21
+ BankTools::GB::Errors::SORT_CODE_WITH_WRONG_LENGTH # => :sort_code_with_wrong_length
22
+ BankTools::GB::Errors::ACCOUNT_NUMBER_INVALID_CHARACTERS # => :account_number_invalid_characters
23
+ BankTools::GB::Errors::SORT_CODE_INVALID_CHARACTERS # => :sort_code_invalid_characters
24
+
25
+ ## Installation
26
+
27
+ Add this line to your application's Gemfile:
28
+
29
+ gem "banktools-gb"
30
+
31
+ And then execute:
32
+
33
+ $ bundle
34
+
35
+ Or install it yourself as:
36
+
37
+ $ gem install banktools-gb
38
+
39
+ ## Tests
40
+
41
+ bundle
42
+ rspec # or: rake
43
+
44
+ ## TODO
45
+
46
+ * Make separation between sort code and account number less naive (could possible be fixed by normalisation).
47
+ * Add errors
48
+ * Mooore tests!
49
+
50
+ ## Also see
51
+
52
+ * [BankTools::SE (Swedish)](https://github.com/barsoom/banktools-se)
53
+ * [BankTools::DE (German)](https://github.com/barsoom/banktools-de)
54
+ * [BankTools::DK (German)](https://github.com/barsoom/banktools-dk)
55
+
56
+ ## Credits
57
+
58
+ * [Hayden Ball](https://github.com/ball-hayden) for creating [UkAccountValidator](https://github.com/ball-hayden/uk_account_validator) that we base this gem on.
59
+
60
+ ## Contributing
61
+
62
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/banktools-gb.
63
+
64
+ ## License
65
+
66
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "banktools-gb/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "banktools-gb"
8
+ spec.version = Banktools::Gb::VERSION
9
+ spec.authors = ["Tomas Skogberg"]
10
+ spec.email = ["tomas@auctionet.com"]
11
+
12
+ spec.summary = %q{Validate and normalise United Kingdom bank account numbers.}
13
+ spec.homepage = "https://github.com/barsoom/banktools-gb"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "uk_account_validator", "~> 0.0.3"
22
+ spec.add_dependency "attr_extras", "~> 4.6"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.11"
25
+ spec.add_development_dependency "rake", "~> 11"
26
+ spec.add_development_dependency "rspec", "~> 3"
27
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "banktools/gb"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,60 @@
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
+ UkAccountValidator::Validator.new(compact_account_number, compact_sort_code).valid?
17
+ end
18
+
19
+ def errors
20
+ errors = []
21
+ errors << :account_number_too_short if account_number_too_short?
22
+ errors << :account_number_too_long if account_number_too_long?
23
+ errors << :sort_code_with_wrong_length if sort_code_with_wrong_length?
24
+ errors << :sort_code_invalid_characters if any_non_digits?(compact_sort_code)
25
+ errors << :account_number_invalid_characters if any_non_digits?(compact_account_number)
26
+ errors
27
+ end
28
+
29
+ private
30
+
31
+ def sort_code_with_wrong_length?
32
+ compact_sort_code.length != SORT_CODE_LENGTH
33
+ end
34
+
35
+ def account_number_too_short?
36
+ compact_account_number.length < ACCOUNT_NUMBER_MIN_LENGTH
37
+ end
38
+
39
+ def account_number_too_long?
40
+ compact_account_number.length > ACCOUNT_NUMBER_MAX_LENGTH
41
+ end
42
+
43
+ def any_non_digits?(number)
44
+ number.match(/\D/)
45
+ end
46
+
47
+ def compact_sort_code
48
+ compact(sort_code)
49
+ end
50
+
51
+ def compact_account_number
52
+ compact(account_number)
53
+ end
54
+
55
+ def compact(number)
56
+ number.gsub(/[\s-]/, "")
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,11 @@
1
+ module Banktools
2
+ module GB
3
+ module Errors
4
+ ACCOUNT_NUMBER_TOO_SHORT = :account_number_too_short
5
+ ACCOUNT_NUMBER_TOO_LONG = :account_number_too_long
6
+ SORT_CODE_WITH_WRONG_LENGTH = :sort_code_with_wrong_length
7
+ SORT_CODE_INVALID_CHARACTERS = :sort_code_invalid_characters
8
+ ACCOUNT_NUMBER_INVALID_CHARACTERS = :account_number_invalid_characters
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ module Banktools
2
+ module Gb
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ require "uk_account_validator"
2
+
3
+ require "banktools-gb/version"
4
+ require "banktools-gb/account_number_with_sort_code"
5
+ require "banktools-gb/errors"
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: banktools-gb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tomas Skogberg
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-06-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: uk_account_validator
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.0.3
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.0.3
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: '4.6'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '4.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.11'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.11'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '11'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '11'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3'
83
+ description:
84
+ email:
85
+ - tomas@auctionet.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - banktools-gb.gemspec
97
+ - bin/console
98
+ - bin/setup
99
+ - lib/banktools-gb.rb
100
+ - lib/banktools-gb/account_number_with_sort_code.rb
101
+ - lib/banktools-gb/errors.rb
102
+ - lib/banktools-gb/version.rb
103
+ homepage: https://github.com/barsoom/banktools-gb
104
+ licenses:
105
+ - MIT
106
+ metadata: {}
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubyforge_project:
123
+ rubygems_version: 2.5.1
124
+ signing_key:
125
+ specification_version: 4
126
+ summary: Validate and normalise United Kingdom bank account numbers.
127
+ test_files: []