bank-contact 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/bank/bic.rb +13 -12
- data/lib/bank/iban.rb +1 -1
- data/lib/bank/version.rb +1 -1
- data/spec/bic_spec.rb +6 -21
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 956289106e81aeb5209fe45c020dd92ffd1caca7
|
4
|
+
data.tar.gz: 25afd8a545784de7c02bd094b1b34f1e1d44e307
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f26c8171bd9cf7d190e01623c2aac84ada412d0624deb437e08ffbfa9854e69546455a2d5d3760de189e18e7b7dcc45f4a494583a030bd44a2e6016a295922da
|
7
|
+
data.tar.gz: ccdf67e7d84b59d23ffc6611b01829cb924ad5b22ab64addf7a1baecebcbcd9cd6d0180872973ac36444a8fc21ba5035b4d19bab40181a650564b8920479837c
|
data/lib/bank/bic.rb
CHANGED
@@ -2,12 +2,14 @@ require 'bank/validators/bic_validator' if defined? ActiveModel
|
|
2
2
|
|
3
3
|
module Bank
|
4
4
|
class BIC
|
5
|
+
REGEX = /^([A-Z]{4})([A-Z]{2})([A-Z0-9]{2})([A-Z0-9]{3})?$/.freeze
|
6
|
+
|
5
7
|
def self.valid?(code)
|
6
8
|
new(code).valid?
|
7
9
|
end
|
8
10
|
|
9
11
|
def initialize(code)
|
10
|
-
@code = code.to_s.
|
12
|
+
@code = code.to_s.gsub(/\s+/, '').upcase
|
11
13
|
end
|
12
14
|
|
13
15
|
def bank_code
|
@@ -27,7 +29,11 @@ module Bank
|
|
27
29
|
end
|
28
30
|
|
29
31
|
def to_s(formatted=false)
|
30
|
-
formatted ?
|
32
|
+
formatted ? to_formatted_str : @code
|
33
|
+
end
|
34
|
+
|
35
|
+
def to_formatted_str
|
36
|
+
"#{bank_code} #{country_code} #{location_code} #{branch_code}".strip
|
31
37
|
end
|
32
38
|
|
33
39
|
def test?
|
@@ -43,24 +49,19 @@ module Bank
|
|
43
49
|
end
|
44
50
|
|
45
51
|
def valid?
|
46
|
-
|
47
|
-
end
|
48
|
-
|
49
|
-
def valid_length?
|
50
|
-
@code.length == 8 || @code.length == 11
|
52
|
+
valid_format? && valid_location_code? && valid_branch_code?
|
51
53
|
end
|
52
54
|
|
53
55
|
def valid_format?
|
54
|
-
|
56
|
+
!!@code[REGEX]
|
55
57
|
end
|
56
58
|
|
57
59
|
def valid_location_code?
|
58
|
-
location_code
|
60
|
+
!location_code.start_with?('0', '1') && !location_code.end_with?('O')
|
59
61
|
end
|
60
62
|
|
61
63
|
def valid_branch_code?
|
62
|
-
branch_code.
|
64
|
+
branch_code.empty? || branch_code == 'XXX' || !branch_code.start_with?('X')
|
63
65
|
end
|
64
|
-
|
65
66
|
end
|
66
|
-
end
|
67
|
+
end
|
data/lib/bank/iban.rb
CHANGED
data/lib/bank/version.rb
CHANGED
data/spec/bic_spec.rb
CHANGED
@@ -21,24 +21,6 @@ describe Bank::BIC do
|
|
21
21
|
@bic.branch_code.must_equal 'XXX'
|
22
22
|
end
|
23
23
|
|
24
|
-
[8, 11].each do |len|
|
25
|
-
describe 'x' * len do
|
26
|
-
it 'has a valid length' do
|
27
|
-
Bank::BIC.new('x' * len).valid_length?.must_equal true
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
1.upto(20) do |len|
|
33
|
-
if len != 8 && len != 11
|
34
|
-
describe 'x' * len do
|
35
|
-
it 'has a valid length' do
|
36
|
-
Bank::BIC.new('x' * len).valid_length?.must_equal false
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
24
|
[
|
43
25
|
'UCJAES2MXXX',
|
44
26
|
'ABAGATWWXXX',
|
@@ -46,17 +28,20 @@ describe Bank::BIC do
|
|
46
28
|
].each do |code|
|
47
29
|
describe code do
|
48
30
|
it 'has a valid format' do
|
49
|
-
Bank::BIC.new(code).
|
31
|
+
Bank::BIC.new(code).valid?.must_equal true
|
50
32
|
end
|
51
33
|
end
|
52
34
|
end
|
53
35
|
|
54
36
|
[
|
55
|
-
'12341234'
|
37
|
+
'12341234', # only digits
|
38
|
+
'UCJAES2MXAA', # branch code starts with 'X'
|
39
|
+
'UCJAES2MAA', # too short
|
40
|
+
'UCJAES2M0001' # too long
|
56
41
|
].each do |code|
|
57
42
|
describe code do
|
58
43
|
it 'has an invalid format' do
|
59
|
-
Bank::BIC.new(code).
|
44
|
+
Bank::BIC.new(code).valid?.must_equal false
|
60
45
|
end
|
61
46
|
end
|
62
47
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bank-contact
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-08-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -114,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
114
114
|
version: '0'
|
115
115
|
requirements: []
|
116
116
|
rubyforge_project:
|
117
|
-
rubygems_version: 2.
|
117
|
+
rubygems_version: 2.4.8
|
118
118
|
signing_key:
|
119
119
|
specification_version: 4
|
120
120
|
summary: IBAN + SWIFT/BIC
|