banktools-se 3.2.0 → 3.3.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 +4 -4
- data/.github/dependabot.yml +6 -0
- data/.github/workflows/ci.yml +9 -6
- data/CHANGELOG.md +4 -0
- data/Gemfile +0 -1
- data/banktools-se.gemspec +5 -1
- data/lib/banktools-se/account/clearing_number.rb +1 -0
- data/lib/banktools-se/plusgiro.rb +6 -3
- data/lib/banktools-se/utils.rb +4 -4
- data/lib/banktools-se/version.rb +1 -1
- data/spec/account_spec.rb +5 -25
- data/spec/plusgiro_spec.rb +3 -2
- metadata +6 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 600245bcaff1e259996286998821855e9e4193222d8d335b10adc46a26b16648
|
|
4
|
+
data.tar.gz: 8daa94ebc4db1d562b0b7b8546732ca4cd987a583245ad56dd0af738beb5349a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4794736dd16c9390a3f2536e59cdb3a988a0039dbcc4b641361db9955f0c787647f2a178e3e0e3289962ab0be42fcbcb0509dd284a6c2bd58cf357075c61dbaf
|
|
7
|
+
data.tar.gz: 6d5cb0c57e1fdce708b5b77761be6db8a1e6390baf730a347c8241dbf5d22378d282b8de8baf66c07463462dc8a7fc531e8c632858f3fe2f34715895c6c5f5c1
|
data/.github/workflows/ci.yml
CHANGED
|
@@ -7,19 +7,22 @@ on:
|
|
|
7
7
|
branches: [ master ]
|
|
8
8
|
|
|
9
9
|
jobs:
|
|
10
|
-
|
|
10
|
+
ruby-versions:
|
|
11
|
+
uses: ruby/actions/.github/workflows/ruby_versions.yml@master
|
|
12
|
+
with:
|
|
13
|
+
min_version: 3.2
|
|
14
|
+
engine: cruby
|
|
11
15
|
|
|
16
|
+
test:
|
|
17
|
+
needs: ruby-versions
|
|
12
18
|
runs-on: ubuntu-latest
|
|
13
19
|
|
|
14
20
|
strategy:
|
|
15
21
|
matrix:
|
|
16
|
-
ruby-version:
|
|
17
|
-
- 3.1
|
|
18
|
-
- "3.0"
|
|
19
|
-
- 2.7
|
|
22
|
+
ruby-version: ${{ fromJson(needs.ruby-versions.outputs.versions) }}
|
|
20
23
|
|
|
21
24
|
steps:
|
|
22
|
-
- uses: actions/checkout@
|
|
25
|
+
- uses: actions/checkout@v6
|
|
23
26
|
- name: Set up Ruby ${{ matrix.ruby-version }}
|
|
24
27
|
uses: ruby/setup-ruby@v1
|
|
25
28
|
with:
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 3.3.0
|
|
4
|
+
|
|
5
|
+
- Add Lunar Bank clearing number range. [#14](https://github.com/barsoom/banktools-se/pull/14). Thanks, @andyglim!
|
|
6
|
+
|
|
3
7
|
## 3.2.0
|
|
4
8
|
|
|
5
9
|
- Add Account#normalize keyword arguments `digits_only`, `clearing_checksum`. [#11](https://github.com/barsoom/banktools-se/pull/11)
|
data/Gemfile
CHANGED
data/banktools-se.gemspec
CHANGED
|
@@ -13,5 +13,9 @@ Gem::Specification.new do |s|
|
|
|
13
13
|
s.files = `git ls-files`.split("\n")
|
|
14
14
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
|
15
15
|
s.require_paths = [ "lib" ]
|
|
16
|
-
s.metadata = {
|
|
16
|
+
s.metadata = {
|
|
17
|
+
"rubygems_mfa_required" => "true",
|
|
18
|
+
"source_code_uri" => "https://github.com/barsoom/banktools-se",
|
|
19
|
+
"changelog_uri" => "https://github.com/barsoom/banktools-se/blob/v#{BankTools::SE::VERSION}/CHANGELOG.md",
|
|
20
|
+
}
|
|
17
21
|
end
|
|
@@ -53,6 +53,7 @@ module BankTools
|
|
|
53
53
|
9680..9689 => { name: "Bluestep Finance" },
|
|
54
54
|
9690..9699 => { name: "Folkia" },
|
|
55
55
|
9700..9709 => { name: "Ekobanken" },
|
|
56
|
+
9710..9719 => { name: "Lunar Bank" },
|
|
56
57
|
9720..9729 => { name: "Netfonds Bank (ub)" },
|
|
57
58
|
9750..9759 => { name: "Northmill Bank" },
|
|
58
59
|
9770..9779 => { name: "FTCS" },
|
|
@@ -4,6 +4,9 @@ module BankTools
|
|
|
4
4
|
|
|
5
5
|
# Could sadly not find anything more authoritative than
|
|
6
6
|
# http://pellesoft.se/communicate/forum/view.aspx?msgid=267449&forumid=63&sum=0
|
|
7
|
+
# https://www.nordea.se/foretag/kundservice/fragor-och-svar-konton.html#faq=Kontouppgifter+432454
|
|
8
|
+
MAX_LENGTH = 10
|
|
9
|
+
MIN_LENGTH = 2
|
|
7
10
|
|
|
8
11
|
attr_reader :number
|
|
9
12
|
|
|
@@ -18,8 +21,8 @@ module BankTools
|
|
|
18
21
|
def errors
|
|
19
22
|
errors = []
|
|
20
23
|
|
|
21
|
-
errors << Errors::TOO_SHORT if digits.length <
|
|
22
|
-
errors << Errors::TOO_LONG if digits.length >
|
|
24
|
+
errors << Errors::TOO_SHORT if digits.length < MIN_LENGTH
|
|
25
|
+
errors << Errors::TOO_LONG if digits.length > MAX_LENGTH
|
|
23
26
|
errors << Errors::INVALID_CHARACTERS if number.to_s.match(/[^0-9 -]/)
|
|
24
27
|
errors << Errors::BAD_CHECKSUM unless Utils.valid_luhn?(number)
|
|
25
28
|
|
|
@@ -29,7 +32,7 @@ module BankTools
|
|
|
29
32
|
def normalize
|
|
30
33
|
if valid?
|
|
31
34
|
pre, pairs, post = digits.split(/(\d{2}*)(\d)$/)
|
|
32
|
-
pairs = pairs.split(/(\d\d)/).reject
|
|
35
|
+
pairs = pairs.split(/(\d\d)/).reject(&:empty?)
|
|
33
36
|
[ pre, pairs.join(" "), "-", post ].join
|
|
34
37
|
else
|
|
35
38
|
number
|
data/lib/banktools-se/utils.rb
CHANGED
|
@@ -4,22 +4,22 @@ module BankTools
|
|
|
4
4
|
|
|
5
5
|
# Based on http://blog.internautdesign.com/2007/4/18/ruby-luhn-check-aka-mod-10-formula
|
|
6
6
|
def self.valid_luhn?(number)
|
|
7
|
-
digits = number.to_s.scan(/\d/).reverse.map
|
|
7
|
+
digits = number.to_s.scan(/\d/).reverse.map(&:to_i)
|
|
8
8
|
digits = digits.each_with_index.map { |d, i|
|
|
9
9
|
d *= 2 if i.odd?
|
|
10
10
|
d > 9 ? d - 9 : d
|
|
11
11
|
}
|
|
12
|
-
sum = digits.
|
|
12
|
+
sum = digits.reduce(0) { |m, x| m + x }
|
|
13
13
|
sum % 10 == 0
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
def self.luhn_checksum(number)
|
|
17
|
-
digits = number.to_s.scan(/\d/).reverse.map
|
|
17
|
+
digits = number.to_s.scan(/\d/).reverse.map(&:to_i)
|
|
18
18
|
digits = digits.each_with_index.map { |d, i|
|
|
19
19
|
d *= 2 if i.even?
|
|
20
20
|
d > 9 ? d - 9 : d
|
|
21
21
|
}
|
|
22
|
-
sum = digits.
|
|
22
|
+
sum = digits.reduce(0) { |m, x| m + x }
|
|
23
23
|
mod = 10 - sum % 10
|
|
24
24
|
mod == 10 ? 0 : mod
|
|
25
25
|
end
|
data/lib/banktools-se/version.rb
CHANGED
data/spec/account_spec.rb
CHANGED
|
@@ -64,7 +64,7 @@ RSpec.describe BankTools::SE::Account do
|
|
|
64
64
|
"9550-0000000", # Avanza Bank.
|
|
65
65
|
"9570-0000000000", # Sparbanken Syd.
|
|
66
66
|
"9960-00", # Nordea/Plusgirot.
|
|
67
|
-
|
|
67
|
+
"9710-0000000", # Lunar Bank.
|
|
68
68
|
].each do |number|
|
|
69
69
|
it "should be empty for a valid number like #{number}" do
|
|
70
70
|
expect(BankTools::SE::Account.new(number).errors).to eq([])
|
|
@@ -112,6 +112,7 @@ RSpec.describe BankTools::SE::Account do
|
|
|
112
112
|
expect(BankTools::SE::Account.new("11550000001").bank).to eq("Nordea")
|
|
113
113
|
expect(BankTools::SE::Account.new("11990000009").bank).to eq("Nordea")
|
|
114
114
|
expect(BankTools::SE::Account.new("12000000005").bank).to eq("Danske Bank")
|
|
115
|
+
expect(BankTools::SE::Account.new("97100000000").bank).to eq("Lunar Bank")
|
|
115
116
|
end
|
|
116
117
|
|
|
117
118
|
it "should return nil for unknown clearing numbers" do
|
|
@@ -163,41 +164,20 @@ RSpec.describe BankTools::SE::Account do
|
|
|
163
164
|
end
|
|
164
165
|
|
|
165
166
|
context "using digits_only: true" do
|
|
166
|
-
it "normalizes
|
|
167
|
+
it "normalizes without any non-digit separators" do
|
|
168
|
+
expect(BankTools::SE::Account.new("1100-0000007").normalize(digits_only: true)).to eq("11000000007")
|
|
167
169
|
expect(BankTools::SE::Account.new("11000000007").normalize(digits_only: true)).to eq("11000000007")
|
|
168
170
|
end
|
|
169
171
|
|
|
170
|
-
it "keeps any Swedbank/Sparbanker clearing checksum" do
|
|
171
|
-
expect(BankTools::SE::Account.new("8000-2-0000000000").normalize(digits_only: true)).to eq("800020000000000")
|
|
172
|
-
end
|
|
173
|
-
|
|
174
172
|
it "does not attempt to normalize invalid numbers" do
|
|
175
173
|
expect(BankTools::SE::Account.new(" 1-2-3 ").normalize(digits_only: true)).to eq(" 1-2-3 ")
|
|
176
174
|
end
|
|
177
|
-
|
|
178
|
-
it "prepends zeroes to the serial number if necessary" do
|
|
179
|
-
expect(BankTools::SE::Account.new("8000-2-80000003").normalize(digits_only: true)).to eq("800020080000003")
|
|
180
|
-
expect(BankTools::SE::Account.new("8000-2-8000000003").normalize(digits_only: true)).to eq("800028000000003")
|
|
181
|
-
end
|
|
182
175
|
end
|
|
183
176
|
|
|
184
177
|
context "using clearing_checksum: false" do
|
|
185
|
-
it "
|
|
186
|
-
expect(BankTools::SE::Account.new("1100 0000007").normalize(clearing_checksum: false)).to eq("1100-0000007")
|
|
187
|
-
end
|
|
188
|
-
|
|
189
|
-
it "drops any Swedbank/Sparbanker clearing checksum" do
|
|
178
|
+
it "drops any Swedbank/Sparbanker clearing checksum (fifth digit and hyphen)" do
|
|
190
179
|
expect(BankTools::SE::Account.new("8000-2-0000000000").normalize(clearing_checksum: false)).to eq("8000-0000000000")
|
|
191
180
|
end
|
|
192
|
-
|
|
193
|
-
it "keeps any invalid numbers" do
|
|
194
|
-
expect(BankTools::SE::Account.new(" 1-2-3 ").normalize(clearing_checksum: false)).to eq(" 1-2-3 ")
|
|
195
|
-
end
|
|
196
|
-
|
|
197
|
-
it "prepends zeroes to the serial number if necessary" do
|
|
198
|
-
expect(BankTools::SE::Account.new("8000-2-80000003").normalize(clearing_checksum: false)).to eq("8000-0080000003")
|
|
199
|
-
expect(BankTools::SE::Account.new("8000-2-8000000003").normalize(clearing_checksum: false)).to eq("8000-8000000003")
|
|
200
|
-
end
|
|
201
181
|
end
|
|
202
182
|
end
|
|
203
183
|
end
|
data/spec/plusgiro_spec.rb
CHANGED
|
@@ -26,6 +26,7 @@ RSpec.describe BankTools::SE::Plusgiro do
|
|
|
26
26
|
[
|
|
27
27
|
"28 65 43-4", # IKEA
|
|
28
28
|
"410 54 68-5", # IKEA
|
|
29
|
+
"421 880 87-25", # Göteborg Dödsbotjänster AB
|
|
29
30
|
"4-2", # Sveriges riksbank
|
|
30
31
|
].each do |number|
|
|
31
32
|
it "should be empty for a valid number like #{number}" do
|
|
@@ -40,8 +41,8 @@ RSpec.describe BankTools::SE::Plusgiro do
|
|
|
40
41
|
expect(BankTools::SE::Plusgiro.new("1---------").errors).to include(BankTools::SE::Errors::TOO_SHORT)
|
|
41
42
|
end
|
|
42
43
|
|
|
43
|
-
it "should include :too_long for numbers longer than
|
|
44
|
-
expect(BankTools::SE::Plusgiro.new("410 54 68-51").errors).to include(BankTools::SE::Errors::TOO_LONG)
|
|
44
|
+
it "should include :too_long for numbers longer than 10 digits" do
|
|
45
|
+
expect(BankTools::SE::Plusgiro.new("410 54 68-51 21").errors).to include(BankTools::SE::Errors::TOO_LONG)
|
|
45
46
|
end
|
|
46
47
|
|
|
47
48
|
it "should include :invalid_characters for numbers with other character than digits, spaces and dashes" do
|
metadata
CHANGED
|
@@ -1,22 +1,21 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: banktools-se
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.
|
|
4
|
+
version: 3.3.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Henrik Nyh
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies: []
|
|
13
|
-
description:
|
|
14
12
|
email:
|
|
15
13
|
- henrik@barsoom.se
|
|
16
14
|
executables: []
|
|
17
15
|
extensions: []
|
|
18
16
|
extra_rdoc_files: []
|
|
19
17
|
files:
|
|
18
|
+
- ".github/dependabot.yml"
|
|
20
19
|
- ".github/workflows/ci.yml"
|
|
21
20
|
- ".gitignore"
|
|
22
21
|
- ".rspec"
|
|
@@ -45,7 +44,8 @@ homepage: ''
|
|
|
45
44
|
licenses: []
|
|
46
45
|
metadata:
|
|
47
46
|
rubygems_mfa_required: 'true'
|
|
48
|
-
|
|
47
|
+
source_code_uri: https://github.com/barsoom/banktools-se
|
|
48
|
+
changelog_uri: https://github.com/barsoom/banktools-se/blob/v3.3.1/CHANGELOG.md
|
|
49
49
|
rdoc_options: []
|
|
50
50
|
require_paths:
|
|
51
51
|
- lib
|
|
@@ -60,8 +60,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
60
60
|
- !ruby/object:Gem::Version
|
|
61
61
|
version: '0'
|
|
62
62
|
requirements: []
|
|
63
|
-
rubygems_version:
|
|
64
|
-
signing_key:
|
|
63
|
+
rubygems_version: 4.0.8
|
|
65
64
|
specification_version: 4
|
|
66
65
|
summary: Validate and normalize Swedish bank account numbers, plusgiro and bankgiro.
|
|
67
66
|
test_files: []
|