bank-contact 0.0.4 → 0.0.5

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: a634611f8033bbb771984e23f9c52d0d42430358
4
- data.tar.gz: aee62a415954e8aebd42d3cc257301a6a975987a
3
+ metadata.gz: 956289106e81aeb5209fe45c020dd92ffd1caca7
4
+ data.tar.gz: 25afd8a545784de7c02bd094b1b34f1e1d44e307
5
5
  SHA512:
6
- metadata.gz: c20be34292875bb16535a1f4bd70949f84488ac89ab340b4edce6c7be0e7ff3fdfc3ee1dce936962441dcb3634823d6244abd93290cfcb8ca6bb1c7686785bef
7
- data.tar.gz: 5d0086e752090a6dd1f15a4d595ff4827a73e40abc81177068d286d090d8daecce690fdfd5041417e9e19233a706915e5e7ceb2cc9c30bc3cd94f81f72b7f6dc
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.strip.gsub(/\s+/, '').upcase
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 ? "#{bank_code} #{country_code} #{location_code} #{branch_code}".strip : @code
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
- valid_length? && valid_format? && valid_location_code? && valid_branch_code?
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
- !!(@code =~ /^[A-Z]{4}[A-Z]{2}[A-Z0-9]{2}([A-Z0-9]{3})?$/)
56
+ !!@code[REGEX]
55
57
  end
56
58
 
57
59
  def valid_location_code?
58
- location_code[0] != '0' && location_code[0] != '1' && location_code[1] != 'O'
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.nil? || !(branch_code[0] == 'X' && branch_code != 'XXX')
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
@@ -12,7 +12,7 @@ module Bank
12
12
  end
13
13
 
14
14
  def initialize(code)
15
- @code = code.to_s.strip.gsub(/\s+/, '').upcase
15
+ @code = code.to_s.gsub(/\s+/, '').upcase
16
16
  end
17
17
 
18
18
  def country_code
data/lib/bank/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Bank
2
- VERSION = '0.0.4'
2
+ VERSION = '0.0.5'
3
3
  end
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).valid_format?.must_equal true
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).valid_format?.must_equal false
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
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: 2014-06-16 00:00:00.000000000 Z
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.2.2
117
+ rubygems_version: 2.4.8
118
118
  signing_key:
119
119
  specification_version: 4
120
120
  summary: IBAN + SWIFT/BIC