banktools-de 0.0.1 → 0.0.2

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
  SHA1:
3
- metadata.gz: b78faf6270b41240ca4265c79c4bc628353a7d30
4
- data.tar.gz: 33a87d445276e51cbef63049034cbc49eb2bad70
3
+ metadata.gz: 010b6ad5764da47d0eee569b99a8494b4ea73d52
4
+ data.tar.gz: e02e69d013380a473866a788a04013831d8d775a
5
5
  SHA512:
6
- metadata.gz: be1e8813bbb8b0cfb0cccf337563ea000a693ad12e5a94a29c3bb2b2b0920956d2afd4cc753e5c4c284843035d28810e43342e30bf0fd4f395fb8dd1bb8f782c
7
- data.tar.gz: 6032a660b7646be3b186d0eeeba23f383d52d2a4a86b633645fc1ca621d6d2a1a2a2ad0827ed61559d1d6b89da7b47f2ee2062a0202242b19ba44aaa1d2f8b8d
6
+ metadata.gz: 76cac880128d73863d1d75a8d3eecb4db6f1121f06268b34a298504b3b8974312214334b9e4ef8b67be3cf0404f92c85927fabe8bf9b847fa133d10c0f3367dd
7
+ data.tar.gz: 9d9fc8c51b69eac2fcadf788caf721eaf39f65cc37156366c084d33bf5101518a44cd0c442c48420af0696002d24f909f5db6cbdd4fb41cc462b6e0316f320c5
data/README.md CHANGED
@@ -1,46 +1,62 @@
1
1
  # German bank tools
2
2
 
3
- Ruby gem to validate, normalize/prettify and to some extent interpret German Bankleitzahl (BLZ) and bank account numbers.
3
+ Ruby gem to validate, normalize/prettify and interpret German Bankleitzahl (BLZ) and bank account numbers.
4
4
 
5
- ## Installation
6
-
7
- Add this line to your application's Gemfile:
8
-
9
- gem 'banktools-de'
10
-
11
- And then execute:
12
-
13
- $ bundle
5
+ When in doubt, this library aims to err on the side of allowing too much.
14
6
 
15
- Or install it yourself as:
7
+ If we got anything wrong, please file an issue or contribute a fix yourself.
16
8
 
17
- $ gem install banktools-de
18
9
 
19
10
  ## Usage
20
11
 
21
12
  (Very much in progress. Expect this list to change rapidly.)
22
13
 
14
+ # BLZ
15
+
23
16
  blz = BankTools::DE::BLZ.new("10070024")
24
17
  blz.normalize # => "100 700 24"
18
+ blz.valid? # => true
19
+ blz.errors # => []
20
+
21
+ bad_blz = BankTools::DE::BLZ.new("1X")
22
+ bad_blz.valid? # => false
23
+ bad_blz.errors # => [ :too_short, :invalid_characters ]
24
+ bad_account.normalize # => "1X"
25
+
25
26
 
26
27
  ## Tests
27
28
 
28
29
  rspec
29
30
  # or: rake
30
31
 
32
+
33
+ ## Installation
34
+
35
+ Add this line to your application's Gemfile:
36
+
37
+ gem 'banktools-de'
38
+
39
+ And then execute:
40
+
41
+ $ bundle
42
+
43
+ Or install it yourself as:
44
+
45
+ $ gem install banktools-de
46
+
47
+
31
48
  ## Also see
32
49
 
33
50
  * [BankTools::SE (Swedish)](https://github.com/barsoom/banktools-se)
34
51
  * [iban-tools](https://github.com/iulianu/iban-tools)
35
52
 
53
+
36
54
  ## Credits and license
37
55
 
38
56
  By [Henrik Nyh](http://henrik.nyh.se) for [Barsoom](http://barsoom.se) under the MIT license:
39
57
 
40
58
  Copyright (c) 2014 Barsoom AB
41
59
 
42
- MIT License
43
-
44
60
  Permission is hereby granted, free of charge, to any person obtaining
45
61
  a copy of this software and associated documentation files (the
46
62
  "Software"), to deal in the Software without restriction, including
@@ -1,8 +1,11 @@
1
1
  require "attr_extras"
2
+ require "bank_tools/de/errors"
2
3
 
3
4
  module BankTools
4
5
  module DE
5
6
  class BLZ
7
+ LENGTH = 8
8
+
6
9
  pattr_initialize :original_value
7
10
 
8
11
  def normalize
@@ -13,6 +16,18 @@ module BankTools
13
16
  end
14
17
  end
15
18
 
19
+ def valid?
20
+ errors.empty?
21
+ end
22
+
23
+ def errors
24
+ errors = []
25
+ errors << Errors::TOO_SHORT if compacted_value.length < LENGTH
26
+ errors << Errors::TOO_LONG if compacted_value.length > LENGTH
27
+ errors << Errors::INVALID_CHARACTERS if compacted_value.match(/\D/)
28
+ errors
29
+ end
30
+
16
31
  private
17
32
 
18
33
  def compacted_value
@@ -0,0 +1,9 @@
1
+ module BankTools
2
+ module DE
3
+ module Errors
4
+ TOO_SHORT = :too_short
5
+ TOO_LONG = :too_long
6
+ INVALID_CHARACTERS = :invalid_characters
7
+ end
8
+ end
9
+ end
@@ -1,5 +1,5 @@
1
1
  module BankTools
2
2
  module DE
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
data/spec/blz_spec.rb CHANGED
@@ -16,3 +16,33 @@ describe BankTools::DE::BLZ, "#normalize" do
16
16
  expect(BankTools::DE::BLZ.new(from).normalize).to eq unto
17
17
  end
18
18
  end
19
+
20
+ describe BankTools::DE::BLZ, "#valid?" do
21
+ it "is true with no errors" do
22
+ expect(BankTools::DE::BLZ.new("123 456 78").valid?).to be_true
23
+ end
24
+
25
+ it "is false with errors" do
26
+ expect(BankTools::DE::BLZ.new("1").valid?).to be_false
27
+ end
28
+ end
29
+
30
+ describe BankTools::DE::BLZ, "#errors" do
31
+ Errors = BankTools::DE::Errors
32
+
33
+ it "is empty with no errors" do
34
+ expect(BankTools::DE::BLZ.new("123 456 78").errors).to eq []
35
+ end
36
+
37
+ it "includes TOO_SHORT if below 8 characters" do
38
+ expect(BankTools::DE::BLZ.new("1234567").errors).to include(Errors::TOO_SHORT)
39
+ end
40
+
41
+ it "includes TOO_LONG if above 8 characters" do
42
+ expect(BankTools::DE::BLZ.new("123456789").errors).to include(Errors::TOO_LONG)
43
+ end
44
+
45
+ it "includes INVALID_CHARACTERS if there are non-digits" do
46
+ expect(BankTools::DE::BLZ.new("1X").errors).to include(Errors::INVALID_CHARACTERS)
47
+ end
48
+ end
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.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henrik Nyh
@@ -80,6 +80,7 @@ files:
80
80
  - banktools-de.gemspec
81
81
  - lib/bank_tools/de.rb
82
82
  - lib/bank_tools/de/blz.rb
83
+ - lib/bank_tools/de/errors.rb
83
84
  - lib/bank_tools/de/version.rb
84
85
  - spec/blz_spec.rb
85
86
  - spec/spec_helper.rb