banktools-de 0.0.2 → 0.0.3
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/README.md +13 -1
- data/lib/bank_tools/de/account.rb +47 -0
- data/lib/bank_tools/de/blz.rb +3 -0
- data/lib/bank_tools/de/version.rb +1 -1
- data/spec/account_spec.rb +57 -0
- data/spec/blz_spec.rb +2 -2
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 89114d9d963ca0aaba7ed20b2347965289b4c46e
|
4
|
+
data.tar.gz: bb9412ad2010aa834351d0ec94f4663c950ae1a3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e686988439bb9ef324ded10e87c8d9639db2d97828320ea36a6deb5fac4453c0300e2ddbf9214c814eab261ae0c9dad5e286c0785364aa9e73406d83ec6a3704
|
7
|
+
data.tar.gz: d2a368d77d104022ab247d5cb21b50cbd62ce0b7b2b85e7cb61b1964be62e43e717ed0e43b082e8937b19366ec23ee4f20987c89434033c81367733e377812cf
|
data/README.md
CHANGED
@@ -19,9 +19,21 @@ If we got anything wrong, please file an issue or contribute a fix yourself.
|
|
19
19
|
blz.errors # => []
|
20
20
|
|
21
21
|
bad_blz = BankTools::DE::BLZ.new("1X")
|
22
|
+
bad_blz.normalize # => "1X"
|
22
23
|
bad_blz.valid? # => false
|
23
24
|
bad_blz.errors # => [ :too_short, :invalid_characters ]
|
24
|
-
|
25
|
+
|
26
|
+
# Account
|
27
|
+
|
28
|
+
account = BankTools::DE::Account.new("123456789")
|
29
|
+
account.normalize # => "123 456 789"
|
30
|
+
account.valid? # => true
|
31
|
+
account.errors # => []
|
32
|
+
|
33
|
+
bad_account = BankTools::DE::Account.new("1")
|
34
|
+
bad_account.normalize # => "1"
|
35
|
+
bad_account.valid? # => false
|
36
|
+
bad_account.errors # => [ :too_short ]
|
25
37
|
|
26
38
|
|
27
39
|
## Tests
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# http://de.wikipedia.org/wiki/Bankleitzahl
|
2
|
+
# http://translate.google.com/translate?hl=en&sl=de&tl=en&u=http%3A%2F%2Fde.wikipedia.org%2Fwiki%2FBankleitzahl
|
3
|
+
|
4
|
+
require "attr_extras"
|
5
|
+
require "bank_tools/de/errors"
|
6
|
+
|
7
|
+
module BankTools
|
8
|
+
module DE
|
9
|
+
class Account
|
10
|
+
# Picked some reasonable values, erring on the side of allowing too much.
|
11
|
+
# Seems to claim max 10: http://docs.oracle.com/cd/E18727_01/doc.121/e13483/T359831T498954.htm
|
12
|
+
# Seems to claim 2 - 13: http://www.credit-card.be/BankAccount/ValidationRules.htm#DE_Validation
|
13
|
+
MIN_LENGTH = 2
|
14
|
+
MAX_LENGTH = 15
|
15
|
+
|
16
|
+
GROUPS_OF = 3
|
17
|
+
|
18
|
+
pattr_initialize :original_value
|
19
|
+
|
20
|
+
def normalize
|
21
|
+
if valid?
|
22
|
+
compacted_value.scan(/\d{#{GROUPS_OF}}|\d+/).join(" ")
|
23
|
+
else
|
24
|
+
original_value
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def valid?
|
29
|
+
errors.empty?
|
30
|
+
end
|
31
|
+
|
32
|
+
def errors
|
33
|
+
errors = []
|
34
|
+
errors << Errors::TOO_SHORT if compacted_value.length < MIN_LENGTH
|
35
|
+
errors << Errors::TOO_LONG if compacted_value.length > MAX_LENGTH
|
36
|
+
errors << Errors::INVALID_CHARACTERS if compacted_value.match(/\D/)
|
37
|
+
errors
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def compacted_value
|
43
|
+
original_value.to_s.gsub(/[\s-]/, "")
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/lib/bank_tools/de/blz.rb
CHANGED
@@ -0,0 +1,57 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "bank_tools/de/account"
|
3
|
+
|
4
|
+
describe BankTools::DE::Account, "#normalize" do
|
5
|
+
it "groups the number in threes" do
|
6
|
+
expect_normalization "12", "12"
|
7
|
+
expect_normalization "123", "123"
|
8
|
+
expect_normalization "1234", "123 4"
|
9
|
+
expect_normalization "1234567890", "123 456 789 0"
|
10
|
+
end
|
11
|
+
|
12
|
+
it "ignores previous whitespace" do
|
13
|
+
expect_normalization " 1 23 4 ", "123 4"
|
14
|
+
end
|
15
|
+
|
16
|
+
it "ignores previous dashes" do
|
17
|
+
expect_normalization " 1-2-3-4 ", "123 4"
|
18
|
+
end
|
19
|
+
|
20
|
+
it "leaves a bad format as-is" do
|
21
|
+
expect_normalization "hej", "hej"
|
22
|
+
end
|
23
|
+
|
24
|
+
def expect_normalization(from, unto)
|
25
|
+
expect(BankTools::DE::Account.new(from).normalize).to eq unto
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe BankTools::DE::Account, "#valid?" do
|
30
|
+
it "is true with no errors" do
|
31
|
+
expect(BankTools::DE::Account.new("12").valid?).to be_true
|
32
|
+
end
|
33
|
+
|
34
|
+
it "is false with errors" do
|
35
|
+
expect(BankTools::DE::Account.new("1").valid?).to be_false
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe BankTools::DE::Account, "#errors" do
|
40
|
+
Errors = BankTools::DE::Errors
|
41
|
+
|
42
|
+
it "is empty when valid" do
|
43
|
+
expect(BankTools::DE::Account.new(" 1-2 ").errors).to be_empty
|
44
|
+
end
|
45
|
+
|
46
|
+
it "includes TOO_SHORT if below 2 characters" do
|
47
|
+
expect(BankTools::DE::Account.new("1").errors).to include(Errors::TOO_SHORT)
|
48
|
+
end
|
49
|
+
|
50
|
+
it "includes TOO_LONG if above 15 characters" do
|
51
|
+
expect(BankTools::DE::Account.new("1234567890123456").errors).to include(Errors::TOO_LONG)
|
52
|
+
end
|
53
|
+
|
54
|
+
it "includes INVALID_CHARACTERS if there's other things than digits, whitespace and dashes" do
|
55
|
+
expect(BankTools::DE::Account.new("1X").errors).to include(Errors::INVALID_CHARACTERS)
|
56
|
+
end
|
57
|
+
end
|
data/spec/blz_spec.rb
CHANGED
@@ -30,8 +30,8 @@ end
|
|
30
30
|
describe BankTools::DE::BLZ, "#errors" do
|
31
31
|
Errors = BankTools::DE::Errors
|
32
32
|
|
33
|
-
it "is empty
|
34
|
-
expect(BankTools::DE::BLZ.new("123 456 78").errors).to
|
33
|
+
it "is empty if there's 8 digits and possibly whitespace" do
|
34
|
+
expect(BankTools::DE::BLZ.new(" 123 456 78 ").errors).to be_empty
|
35
35
|
end
|
36
36
|
|
37
37
|
it "includes TOO_SHORT if below 8 characters" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: banktools-de
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Henrik Nyh
|
@@ -79,9 +79,11 @@ files:
|
|
79
79
|
- Rakefile
|
80
80
|
- banktools-de.gemspec
|
81
81
|
- lib/bank_tools/de.rb
|
82
|
+
- lib/bank_tools/de/account.rb
|
82
83
|
- lib/bank_tools/de/blz.rb
|
83
84
|
- lib/bank_tools/de/errors.rb
|
84
85
|
- lib/bank_tools/de/version.rb
|
86
|
+
- spec/account_spec.rb
|
85
87
|
- spec/blz_spec.rb
|
86
88
|
- spec/spec_helper.rb
|
87
89
|
homepage: ''
|
@@ -109,5 +111,6 @@ signing_key:
|
|
109
111
|
specification_version: 4
|
110
112
|
summary: Validate and normalize German Bankleitzahl (BLZ) and bank account numbers.
|
111
113
|
test_files:
|
114
|
+
- spec/account_spec.rb
|
112
115
|
- spec/blz_spec.rb
|
113
116
|
- spec/spec_helper.rb
|