nz_bank_account_validator 1.1.0 → 2.0.0
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/.github/workflows/rspec.yml +19 -0
- data/.rubocop.yml +7 -17
- data/CHANGELOG.txt +4 -0
- data/Gemfile +9 -1
- data/README.md +3 -5
- data/lib/nz_bank_account_validator/version.rb +1 -1
- data/lib/nz_bank_account_validator.rb +12 -6
- data/validate_nz_bank_acc.gemspec +14 -20
- metadata +8 -108
- data/.travis.yml +0 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1b444f080d50b4e49daeb139e2b6128d06de70288bde143de2d25ef4e15ab108
|
|
4
|
+
data.tar.gz: bc2c68b1f1116fec411a362cf7084374bf68b6559e4680a5f2368f3245a8f8fe
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8e6584c44301497f95141eb4425fefad87c330857e993439cc275f4ddd679f3d9620034d7a1ac4de727a848f38dbb80f9fd9b5bd997f06659fa0bfe9fed26153
|
|
7
|
+
data.tar.gz: 561cea9c4a1f9799b09f42e11167b1d3d1a6237a9afb2454ae07a8e14dee6eb12148f5fb73bdee823b160548876b644da964be6fc90ad77cf11091b48288ebe1
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
name: rspec
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
pull_request:
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
test:
|
|
9
|
+
runs-on: ubuntu-latest
|
|
10
|
+
strategy:
|
|
11
|
+
matrix:
|
|
12
|
+
ruby: ["3.2", "3.3", "3.4", "4.0"]
|
|
13
|
+
steps:
|
|
14
|
+
- uses: actions/checkout@v4
|
|
15
|
+
- uses: ruby/setup-ruby@v1
|
|
16
|
+
with:
|
|
17
|
+
ruby-version: ${{ matrix.ruby }}
|
|
18
|
+
bundler-cache: true
|
|
19
|
+
- run: bundle exec rspec
|
data/.rubocop.yml
CHANGED
|
@@ -1,33 +1,23 @@
|
|
|
1
|
-
|
|
1
|
+
plugins:
|
|
2
2
|
- rubocop-rspec
|
|
3
3
|
- rubocop-performance
|
|
4
4
|
|
|
5
5
|
AllCops:
|
|
6
|
-
TargetRubyVersion: 2
|
|
6
|
+
TargetRubyVersion: 3.2
|
|
7
|
+
NewCops: enable
|
|
7
8
|
Exclude:
|
|
8
9
|
- .git/
|
|
9
10
|
- bin/*
|
|
10
|
-
- config/deploy/*
|
|
11
11
|
- coverage/**/*
|
|
12
|
-
- db/migrate/*
|
|
13
|
-
- db/schema.rb
|
|
14
12
|
- doc/**/*
|
|
15
13
|
- Gemfile
|
|
16
14
|
- lib/tasks/*.rake
|
|
17
|
-
- log/**/*
|
|
18
|
-
- node_modules/**/*
|
|
19
|
-
- script/*
|
|
20
15
|
- spec/**/*
|
|
21
|
-
- test/**/*
|
|
22
|
-
- tmp/**/*
|
|
23
|
-
- vendor/assets/**/*
|
|
24
|
-
- vendor/gems/*/bin/*
|
|
25
|
-
- vendor/gems/*/spec/**/*
|
|
26
16
|
|
|
27
|
-
Layout/
|
|
17
|
+
Layout/ParameterAlignment:
|
|
28
18
|
EnforcedStyle: with_first_parameter
|
|
29
19
|
|
|
30
|
-
Layout/
|
|
20
|
+
Layout/HashAlignment:
|
|
31
21
|
EnforcedHashRocketStyle: table
|
|
32
22
|
EnforcedColonStyle: table
|
|
33
23
|
|
|
@@ -100,7 +90,7 @@ Style/RegexpLiteral:
|
|
|
100
90
|
Style/IfUnlessModifier:
|
|
101
91
|
Enabled: false
|
|
102
92
|
|
|
103
|
-
|
|
93
|
+
Layout/LineLength:
|
|
104
94
|
Enabled: false
|
|
105
95
|
|
|
106
96
|
Metrics/ClassLength:
|
|
@@ -130,5 +120,5 @@ Metrics/ParameterLists:
|
|
|
130
120
|
Metrics/BlockNesting:
|
|
131
121
|
Enabled: false
|
|
132
122
|
|
|
133
|
-
Naming/
|
|
123
|
+
Naming/MethodParameterName:
|
|
134
124
|
Enabled: false
|
data/CHANGELOG.txt
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
2.0.0 - Drop support for Ruby < 3.2
|
|
2
|
+
Support using either the more common NZBN format or IBAN format (Ben Anderson)
|
|
3
|
+
Support numbers without spacing or hyphens
|
|
4
|
+
Switch from Travis (RIP) to Github Actions
|
|
1
5
|
1.1.0 - Tidy up code, add more bank accounts from updated document
|
|
2
6
|
1.0.0 - First public release
|
|
3
7
|
0.9.0 - Add new ranges from updated IRD document
|
data/Gemfile
CHANGED
data/README.md
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
[](https://travis-ci.org/steveh/nz_bank_account_validator)
|
|
4
|
-
[](https://codeclimate.com/github/steveh/nz_bank_account_validator)
|
|
5
|
-
[](https://codeclimate.com/github/steveh/nz_bank_account_validator/coverage)
|
|
1
|
+
# NZ Bank Account Validator
|
|
6
2
|
|
|
7
3
|
An implementation of the process described on page 10 of the [IRD RWT - NRWT 2008 Specification](https://www.ird.govt.nz/resources/d/8/d8e49dce-1bda-4875-8acf-9ebf908c6e17/rwt-nrwt-spec-2014.pdf).
|
|
8
4
|
|
|
5
|
+
There are no dependencies. All non-EOL versions of Ruby should be supported.
|
|
6
|
+
|
|
9
7
|
|
|
10
8
|
## Installation
|
|
11
9
|
|
|
@@ -18,7 +18,8 @@ class NzBankAccountValidator
|
|
|
18
18
|
end
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
IBAN_PATTERN = /\A^(?<bank_id>\d{1,2})[- ]?(?<bank_branch>\d{1,4})[- ]?(?<account_base_number>\d{1,8})[- ]?(?<account_suffix>\d{1,4})\z/
|
|
22
|
+
NZBN_PATTERN = /\A^(?<bank_id>\d{2})[- ]?(?<bank_branch>\d{4})[- ]?(?<account_base_number>\d{7})[- ]?(?<account_suffix>\d{2,3})\z/
|
|
22
23
|
|
|
23
24
|
RADIX = 10
|
|
24
25
|
|
|
@@ -30,7 +31,7 @@ class NzBankAccountValidator
|
|
|
30
31
|
1 => BankDefinition.new(ranges: [1..999, 1100..1199, 1800..1899]),
|
|
31
32
|
2 => BankDefinition.new(ranges: [1..999, 1200..1299]),
|
|
32
33
|
3 => BankDefinition.new(ranges: [1..999, 1300..1399, 1500..1599, 1700..1799, 1900..1999, 7350..7399]),
|
|
33
|
-
4 => BankDefinition.new(ranges: [
|
|
34
|
+
4 => BankDefinition.new(ranges: [2014..2024]),
|
|
34
35
|
6 => BankDefinition.new(ranges: [1..999, 1400..1499]),
|
|
35
36
|
8 => BankDefinition.new(ranges: [6500..6599], algo: :d),
|
|
36
37
|
9 => BankDefinition.new(ranges: [0..0], algo: :e),
|
|
@@ -76,8 +77,13 @@ class NzBankAccountValidator
|
|
|
76
77
|
new(string).valid?
|
|
77
78
|
end
|
|
78
79
|
|
|
79
|
-
def initialize(string)
|
|
80
|
-
match =
|
|
80
|
+
def initialize(string, iban: false)
|
|
81
|
+
match = if iban
|
|
82
|
+
string.match(IBAN_PATTERN)
|
|
83
|
+
else
|
|
84
|
+
string.match(NZBN_PATTERN)
|
|
85
|
+
end
|
|
86
|
+
|
|
81
87
|
return unless match
|
|
82
88
|
|
|
83
89
|
@bank_id = Integer(match[:bank_id], RADIX)
|
|
@@ -137,12 +143,12 @@ class NzBankAccountValidator
|
|
|
137
143
|
if [:e, :g].include?(algo_code)
|
|
138
144
|
(0...CHECKSUM_DIGITS).inject(0) do |sum, index|
|
|
139
145
|
s = number_for_checksum[index].to_i * algo[index]
|
|
140
|
-
2.times { s = s.to_s.chars.
|
|
146
|
+
2.times { s = s.to_s.chars.sum(&:to_i) }
|
|
141
147
|
sum + s
|
|
142
148
|
end
|
|
143
149
|
else
|
|
144
150
|
(0...CHECKSUM_DIGITS).inject(0) do |sum, index|
|
|
145
|
-
sum + number_for_checksum[index].to_i * algo[index]
|
|
151
|
+
sum + (number_for_checksum[index].to_i * algo[index])
|
|
146
152
|
end
|
|
147
153
|
end
|
|
148
154
|
end
|
|
@@ -5,24 +5,18 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
|
5
5
|
require "nz_bank_account_validator/version"
|
|
6
6
|
|
|
7
7
|
Gem::Specification.new do |spec|
|
|
8
|
-
spec.name
|
|
9
|
-
spec.version
|
|
10
|
-
spec.authors
|
|
11
|
-
spec.email
|
|
12
|
-
spec.summary
|
|
13
|
-
spec.description
|
|
14
|
-
spec.homepage
|
|
15
|
-
spec.license
|
|
16
|
-
spec.files
|
|
17
|
-
spec.bindir
|
|
18
|
-
spec.executables
|
|
19
|
-
spec.require_paths
|
|
20
|
-
|
|
21
|
-
spec.
|
|
22
|
-
spec.add_development_dependency "rake"
|
|
23
|
-
spec.add_development_dependency "rspec"
|
|
24
|
-
spec.add_development_dependency "rubocop"
|
|
25
|
-
spec.add_development_dependency "rubocop-performance"
|
|
26
|
-
spec.add_development_dependency "rubocop-rspec"
|
|
27
|
-
spec.add_development_dependency "simplecov"
|
|
8
|
+
spec.name = "nz_bank_account_validator"
|
|
9
|
+
spec.version = NzBankAccountValidator::VERSION
|
|
10
|
+
spec.authors = ["Steve Hoeksema", "Eaden McKee"]
|
|
11
|
+
spec.email = ["steve@kotiri.com"]
|
|
12
|
+
spec.summary = "Validate a New Zealand bank account number according to IRD specifications"
|
|
13
|
+
spec.description = "Validate a New Zealand bank account number according to IRD specifications"
|
|
14
|
+
spec.homepage = "https://github.com/steveh/nz_bank_account_validator"
|
|
15
|
+
spec.license = "MIT"
|
|
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
|
+
spec.required_ruby_version = ">= 3.2"
|
|
21
|
+
spec.metadata["rubygems_mfa_required"] = "true"
|
|
28
22
|
end
|
metadata
CHANGED
|
@@ -1,114 +1,15 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: nz_bank_account_validator
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 2.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Steve Hoeksema
|
|
8
8
|
- Eaden McKee
|
|
9
|
-
autorequire:
|
|
10
9
|
bindir: exe
|
|
11
10
|
cert_chain: []
|
|
12
|
-
date:
|
|
13
|
-
dependencies:
|
|
14
|
-
- !ruby/object:Gem::Dependency
|
|
15
|
-
name: bundler
|
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
|
17
|
-
requirements:
|
|
18
|
-
- - ">="
|
|
19
|
-
- !ruby/object:Gem::Version
|
|
20
|
-
version: '0'
|
|
21
|
-
type: :development
|
|
22
|
-
prerelease: false
|
|
23
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
24
|
-
requirements:
|
|
25
|
-
- - ">="
|
|
26
|
-
- !ruby/object:Gem::Version
|
|
27
|
-
version: '0'
|
|
28
|
-
- !ruby/object:Gem::Dependency
|
|
29
|
-
name: rake
|
|
30
|
-
requirement: !ruby/object:Gem::Requirement
|
|
31
|
-
requirements:
|
|
32
|
-
- - ">="
|
|
33
|
-
- !ruby/object:Gem::Version
|
|
34
|
-
version: '0'
|
|
35
|
-
type: :development
|
|
36
|
-
prerelease: false
|
|
37
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
38
|
-
requirements:
|
|
39
|
-
- - ">="
|
|
40
|
-
- !ruby/object:Gem::Version
|
|
41
|
-
version: '0'
|
|
42
|
-
- !ruby/object:Gem::Dependency
|
|
43
|
-
name: rspec
|
|
44
|
-
requirement: !ruby/object:Gem::Requirement
|
|
45
|
-
requirements:
|
|
46
|
-
- - ">="
|
|
47
|
-
- !ruby/object:Gem::Version
|
|
48
|
-
version: '0'
|
|
49
|
-
type: :development
|
|
50
|
-
prerelease: false
|
|
51
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
52
|
-
requirements:
|
|
53
|
-
- - ">="
|
|
54
|
-
- !ruby/object:Gem::Version
|
|
55
|
-
version: '0'
|
|
56
|
-
- !ruby/object:Gem::Dependency
|
|
57
|
-
name: rubocop
|
|
58
|
-
requirement: !ruby/object:Gem::Requirement
|
|
59
|
-
requirements:
|
|
60
|
-
- - ">="
|
|
61
|
-
- !ruby/object:Gem::Version
|
|
62
|
-
version: '0'
|
|
63
|
-
type: :development
|
|
64
|
-
prerelease: false
|
|
65
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
66
|
-
requirements:
|
|
67
|
-
- - ">="
|
|
68
|
-
- !ruby/object:Gem::Version
|
|
69
|
-
version: '0'
|
|
70
|
-
- !ruby/object:Gem::Dependency
|
|
71
|
-
name: rubocop-performance
|
|
72
|
-
requirement: !ruby/object:Gem::Requirement
|
|
73
|
-
requirements:
|
|
74
|
-
- - ">="
|
|
75
|
-
- !ruby/object:Gem::Version
|
|
76
|
-
version: '0'
|
|
77
|
-
type: :development
|
|
78
|
-
prerelease: false
|
|
79
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
80
|
-
requirements:
|
|
81
|
-
- - ">="
|
|
82
|
-
- !ruby/object:Gem::Version
|
|
83
|
-
version: '0'
|
|
84
|
-
- !ruby/object:Gem::Dependency
|
|
85
|
-
name: rubocop-rspec
|
|
86
|
-
requirement: !ruby/object:Gem::Requirement
|
|
87
|
-
requirements:
|
|
88
|
-
- - ">="
|
|
89
|
-
- !ruby/object:Gem::Version
|
|
90
|
-
version: '0'
|
|
91
|
-
type: :development
|
|
92
|
-
prerelease: false
|
|
93
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
94
|
-
requirements:
|
|
95
|
-
- - ">="
|
|
96
|
-
- !ruby/object:Gem::Version
|
|
97
|
-
version: '0'
|
|
98
|
-
- !ruby/object:Gem::Dependency
|
|
99
|
-
name: simplecov
|
|
100
|
-
requirement: !ruby/object:Gem::Requirement
|
|
101
|
-
requirements:
|
|
102
|
-
- - ">="
|
|
103
|
-
- !ruby/object:Gem::Version
|
|
104
|
-
version: '0'
|
|
105
|
-
type: :development
|
|
106
|
-
prerelease: false
|
|
107
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
108
|
-
requirements:
|
|
109
|
-
- - ">="
|
|
110
|
-
- !ruby/object:Gem::Version
|
|
111
|
-
version: '0'
|
|
11
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
112
13
|
description: Validate a New Zealand bank account number according to IRD specifications
|
|
113
14
|
email:
|
|
114
15
|
- steve@kotiri.com
|
|
@@ -116,10 +17,10 @@ executables: []
|
|
|
116
17
|
extensions: []
|
|
117
18
|
extra_rdoc_files: []
|
|
118
19
|
files:
|
|
20
|
+
- ".github/workflows/rspec.yml"
|
|
119
21
|
- ".gitignore"
|
|
120
22
|
- ".rspec"
|
|
121
23
|
- ".rubocop.yml"
|
|
122
|
-
- ".travis.yml"
|
|
123
24
|
- CHANGELOG.txt
|
|
124
25
|
- Gemfile
|
|
125
26
|
- LICENSE.md
|
|
@@ -133,8 +34,8 @@ files:
|
|
|
133
34
|
homepage: https://github.com/steveh/nz_bank_account_validator
|
|
134
35
|
licenses:
|
|
135
36
|
- MIT
|
|
136
|
-
metadata:
|
|
137
|
-
|
|
37
|
+
metadata:
|
|
38
|
+
rubygems_mfa_required: 'true'
|
|
138
39
|
rdoc_options: []
|
|
139
40
|
require_paths:
|
|
140
41
|
- lib
|
|
@@ -142,15 +43,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
142
43
|
requirements:
|
|
143
44
|
- - ">="
|
|
144
45
|
- !ruby/object:Gem::Version
|
|
145
|
-
version: '
|
|
46
|
+
version: '3.2'
|
|
146
47
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
147
48
|
requirements:
|
|
148
49
|
- - ">="
|
|
149
50
|
- !ruby/object:Gem::Version
|
|
150
51
|
version: '0'
|
|
151
52
|
requirements: []
|
|
152
|
-
rubygems_version: 3.
|
|
153
|
-
signing_key:
|
|
53
|
+
rubygems_version: 3.6.9
|
|
154
54
|
specification_version: 4
|
|
155
55
|
summary: Validate a New Zealand bank account number according to IRD specifications
|
|
156
56
|
test_files: []
|