banktools-se 3.2.0 → 3.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2171141853a873652da69aa7ccd2c49212b060c34b8438798019178f86717a9e
4
- data.tar.gz: 53ddab54a570de046d7149e26805670068be40b37549a21c121a62295e4dd15b
3
+ metadata.gz: f5d38b29a0e8e17173e684e2aa57595210cd8239a3faad83881e09a2155b47ec
4
+ data.tar.gz: 536681543fe7547f8c5589a09929c3c4273f3de5126f8b56ff88edebea2c02d5
5
5
  SHA512:
6
- metadata.gz: 8bfd4a36644ed06f78b43b22484b8fa9a3c337c5731fb213f9c744138ad3ff5aaed4718765e6c35586feb38535111b6286c0651b9cf39e5a1d7f9e1e0712fb0f
7
- data.tar.gz: 823a913eb6e0a644028679331af9bbff728adf86a4f81a3febd122979408a791ea46e244ebbee403ba649dc1f2157ccef6abee5709ce717551ab0ab0f90e8f30
6
+ metadata.gz: 24b822afa750fd939f09245cecdc18eaf04dbedf9a7a04e8f246c0d5c4d264906817b63f89a7f93b1a73b1dc4d867791c09bb27277546a8536ae055744cd1aed
7
+ data.tar.gz: 2c3c2217e150f37beb61215d64407af6b592bddca513204d520c06c07e5a6da8ae3ee40147d5d2ffeb6b34cea9a553f9239f4e5e51d2d8c05f3d337e9b4adc19
@@ -0,0 +1,6 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: "github-actions"
4
+ directory: "/"
5
+ schedule:
6
+ interval: "weekly"
@@ -7,19 +7,22 @@ on:
7
7
  branches: [ master ]
8
8
 
9
9
  jobs:
10
- test:
10
+ ruby-versions:
11
+ uses: ruby/actions/.github/workflows/ruby_versions.yml@master
12
+ with:
13
+ min_version: 3.1
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@v3
25
+ - uses: actions/checkout@v4
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
@@ -1,6 +1,5 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- # Specify your gem's dependencies in bank-tools-se.gemspec
4
3
  gemspec
5
4
 
6
5
  group :development, :test do
@@ -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" },
@@ -29,7 +29,7 @@ module BankTools
29
29
  def normalize
30
30
  if valid?
31
31
  pre, pairs, post = digits.split(/(\d{2}*)(\d)$/)
32
- pairs = pairs.split(/(\d\d)/).reject { |x| x.empty? }
32
+ pairs = pairs.split(/(\d\d)/).reject(&:empty?)
33
33
  [ pre, pairs.join(" "), "-", post ].join
34
34
  else
35
35
  number
@@ -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 { |x| x.to_i }
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.inject(0) { |m, x| m + x }
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 { |x| x.to_i }
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.inject(0) { |m, x| m + x }
22
+ sum = digits.reduce(0) { |m, x| m + x }
23
23
  mod = 10 - sum % 10
24
24
  mod == 10 ? 0 : mod
25
25
  end
@@ -1,5 +1,5 @@
1
1
  module BankTools
2
2
  module SE
3
- VERSION = "3.2.0"
3
+ VERSION = "3.3.0"
4
4
  end
5
5
  end
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 to clearing number then serial number" do
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 "normalizes to clearing number then serial number" do
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
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.2.0
4
+ version: 3.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henrik Nyh
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2022-06-14 00:00:00.000000000 Z
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,6 @@ homepage: ''
45
44
  licenses: []
46
45
  metadata:
47
46
  rubygems_mfa_required: 'true'
48
- post_install_message:
49
47
  rdoc_options: []
50
48
  require_paths:
51
49
  - lib
@@ -60,8 +58,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
60
58
  - !ruby/object:Gem::Version
61
59
  version: '0'
62
60
  requirements: []
63
- rubygems_version: 3.3.11
64
- signing_key:
61
+ rubygems_version: 3.6.8
65
62
  specification_version: 4
66
63
  summary: Validate and normalize Swedish bank account numbers, plusgiro and bankgiro.
67
64
  test_files: []