bank_account_number_validator 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 +17 -0
- data/bank_account_number_validator.gemspec +1 -1
- data/lib/bank_account_number_validator/validator.rb +11 -5
- data/lib/bank_account_number_validator/validator/pl.rb +5 -1
- data/spec/lib/bank_account_number_validator/validator/pl_spec.rb +24 -12
- data/spec/lib/bank_account_number_validator/validator_spec.rb +41 -13
- data/spec/lib/bank_account_number_validator_spec.rb +4 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 332260d181f0a0a2a193fcdee03520e100531729
|
4
|
+
data.tar.gz: 2553d7f51e5397f6b37f4787784694b3d60a1a8d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 43a20251d77d74c81739b0277e788bc8c75e4c7893e632fbdd8b8fde58cf4da85e439a429ff54924d6a2327d572741a6fe4cddd12ddf5ef07d670dd620755807
|
7
|
+
data.tar.gz: 57a819bdcd0c6c5d5ca072f94f886a53b5bfd1932fcb90e2be4b3036961932553cb7a53156167216a7dc807caae8eabe2a5c5708de529d2754c61b074ef23da7
|
data/README.md
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
#Bank account number validator
|
2
|
+
|
3
|
+
In this version validations only POLISH bank account number validator
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
```ruby
|
7
|
+
gem install bank_account_number_validator
|
8
|
+
```
|
9
|
+
## Installation in GemFile
|
10
|
+
```ruby
|
11
|
+
gem 'bank_account_number_validator'
|
12
|
+
```
|
13
|
+
|
14
|
+
## Usage
|
15
|
+
```ruby
|
16
|
+
validates :number, bank_account_number: true
|
17
|
+
```
|
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |gem|
|
6
6
|
gem.name = "bank_account_number_validator"
|
7
|
-
gem.version = '0.0.
|
7
|
+
gem.version = '0.0.3'
|
8
8
|
gem.authors = ["jacoobb"]
|
9
9
|
gem.email = ["mikrut.jakub@gmail.com"]
|
10
10
|
gem.summary = %q{Bank account number validator}
|
@@ -1,24 +1,30 @@
|
|
1
1
|
class BankAccountNumberValidator::Validator
|
2
2
|
|
3
3
|
def initialize location: nil, value: nil
|
4
|
-
@
|
4
|
+
@value = remote_white_space value
|
5
|
+
@validator = location_valid location
|
5
6
|
end
|
6
7
|
|
7
8
|
def valid
|
9
|
+
return false unless only_numer?
|
8
10
|
@validator.valid
|
9
11
|
end
|
10
12
|
|
11
13
|
|
12
14
|
private
|
13
15
|
|
14
|
-
def
|
15
|
-
value
|
16
|
+
def only_numer?
|
17
|
+
@value =~ /^(?<num>\d+)$/
|
16
18
|
end
|
17
19
|
|
18
|
-
def
|
20
|
+
def remote_white_space value
|
21
|
+
value.gsub(/\s+/, "")
|
22
|
+
end
|
23
|
+
|
24
|
+
def location_valid location
|
19
25
|
case location
|
20
26
|
when :pl
|
21
|
-
BankAccountNumberValidator::Validator::Pl.new value: value
|
27
|
+
BankAccountNumberValidator::Validator::Pl.new value: @value
|
22
28
|
end
|
23
29
|
end
|
24
30
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
class BankAccountNumberValidator::Validator::Pl < BankAccountNumberValidator::Validator
|
2
2
|
def initialize value: nil
|
3
|
-
@value = value
|
3
|
+
@value = value_to_array value
|
4
4
|
@weight = [1,10,3,30,9,90,27,76,81,34,49,5,50,15,53,45,62,38,89,17,73,51,25,56,75,71,31,19,93,57]
|
5
5
|
end
|
6
6
|
|
@@ -13,6 +13,10 @@ class BankAccountNumberValidator::Validator::Pl < BankAccountNumberValidator::Va
|
|
13
13
|
|
14
14
|
|
15
15
|
private
|
16
|
+
|
17
|
+
def value_to_array value
|
18
|
+
value.chars.map{|char| char.to_i}
|
19
|
+
end
|
16
20
|
|
17
21
|
def length_valid
|
18
22
|
@value.size == 26
|
@@ -10,26 +10,38 @@ describe BankAccountNumberValidator::Validator::Pl do
|
|
10
10
|
end
|
11
11
|
|
12
12
|
it "return false if number is too short" do
|
13
|
-
validator = BankAccountNumberValidator::Validator::Pl.new value:
|
13
|
+
validator = BankAccountNumberValidator::Validator::Pl.new value: '123'
|
14
14
|
expect(validator.valid).to be false
|
15
15
|
end
|
16
16
|
|
17
17
|
it "return false if number is too long" do
|
18
|
-
validator = BankAccountNumberValidator::Validator::Pl.new value:
|
18
|
+
validator = BankAccountNumberValidator::Validator::Pl.new value: '11111111111111111111111111111111'
|
19
19
|
expect(validator.valid).to be false
|
20
20
|
end
|
21
21
|
|
22
22
|
it 'call length_valid' do
|
23
23
|
expect_any_instance_of(BankAccountNumberValidator::Validator::Pl).to receive(:length_valid)
|
24
|
-
validator = BankAccountNumberValidator::Validator::Pl.new value:
|
24
|
+
validator = BankAccountNumberValidator::Validator::Pl.new value: '123'
|
25
25
|
validator.valid
|
26
26
|
end
|
27
27
|
|
28
28
|
end
|
29
29
|
|
30
|
+
describe "value_to_array" do
|
31
|
+
it "return array" do
|
32
|
+
validator = BankAccountNumberValidator::Validator::Pl.new value: '123'
|
33
|
+
expect(validator.send(:value_to_array, '123')).to eq [1,2,3]
|
34
|
+
end
|
35
|
+
|
36
|
+
it "call value_to_array" do
|
37
|
+
expect_any_instance_of(BankAccountNumberValidator::Validator::Pl).to receive(:value_to_array).with('123')
|
38
|
+
validator = BankAccountNumberValidator::Validator::Pl.new value: '123'
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
30
42
|
describe "set_pl_code" do
|
31
43
|
it "add code to array" do
|
32
|
-
validator = BankAccountNumberValidator::Validator::Pl.new value:
|
44
|
+
validator = BankAccountNumberValidator::Validator::Pl.new value: '123'
|
33
45
|
expect(validator.send(:set_pl_code)).to eq [1,2,3,2,5,2,1]
|
34
46
|
end
|
35
47
|
|
@@ -39,14 +51,14 @@ describe BankAccountNumberValidator::Validator::Pl do
|
|
39
51
|
allow_any_instance_of(BankAccountNumberValidator::Validator::Pl).to receive(:remainder?)
|
40
52
|
|
41
53
|
expect_any_instance_of(BankAccountNumberValidator::Validator::Pl).to receive(:set_pl_code)
|
42
|
-
validator = BankAccountNumberValidator::Validator::Pl.new value:
|
54
|
+
validator = BankAccountNumberValidator::Validator::Pl.new value: '123'
|
43
55
|
validator.valid
|
44
56
|
end
|
45
57
|
end
|
46
58
|
|
47
59
|
describe "set_first_to_end" do
|
48
60
|
it "set first to end" do
|
49
|
-
validator = BankAccountNumberValidator::Validator::Pl.new value:
|
61
|
+
validator = BankAccountNumberValidator::Validator::Pl.new value: '123'
|
50
62
|
expect(validator.send(:set_first_to_end)).to eq [3,1,2]
|
51
63
|
end
|
52
64
|
|
@@ -56,21 +68,21 @@ describe BankAccountNumberValidator::Validator::Pl do
|
|
56
68
|
allow_any_instance_of(BankAccountNumberValidator::Validator::Pl).to receive(:remainder?)
|
57
69
|
|
58
70
|
expect_any_instance_of(BankAccountNumberValidator::Validator::Pl).to receive(:set_first_to_end)
|
59
|
-
validator = BankAccountNumberValidator::Validator::Pl.new value:
|
71
|
+
validator = BankAccountNumberValidator::Validator::Pl.new value: '123'
|
60
72
|
validator.valid
|
61
73
|
end
|
62
74
|
end
|
63
75
|
|
64
76
|
describe "sum_up_the_weight" do
|
65
77
|
it "set first to end" do
|
66
|
-
validator = BankAccountNumberValidator::Validator::Pl.new value:
|
78
|
+
validator = BankAccountNumberValidator::Validator::Pl.new value: '83101010230000261395100000'
|
67
79
|
expect(validator.send(:sum_up_the_weight)).to eq 2669
|
68
80
|
end
|
69
81
|
|
70
82
|
it "call sum_up_the_weight" do
|
71
83
|
expect_any_instance_of(BankAccountNumberValidator::Validator::Pl).to receive(:sum_up_the_weight).and_return 97
|
72
84
|
|
73
|
-
validator = BankAccountNumberValidator::Validator::Pl.new value:
|
85
|
+
validator = BankAccountNumberValidator::Validator::Pl.new value: '123'
|
74
86
|
validator.send :remainder?
|
75
87
|
end
|
76
88
|
end
|
@@ -78,13 +90,13 @@ describe BankAccountNumberValidator::Validator::Pl do
|
|
78
90
|
describe 'remainder?' do
|
79
91
|
it "return true " do
|
80
92
|
allow_any_instance_of(BankAccountNumberValidator::Validator::Pl).to receive(:sum_up_the_weight).and_return 98
|
81
|
-
validator = BankAccountNumberValidator::Validator::Pl.new value:
|
93
|
+
validator = BankAccountNumberValidator::Validator::Pl.new value: '83'
|
82
94
|
expect(validator.send(:remainder?)).to be true
|
83
95
|
end
|
84
96
|
|
85
97
|
it "return false" do
|
86
98
|
allow_any_instance_of(BankAccountNumberValidator::Validator::Pl).to receive(:sum_up_the_weight).and_return 97
|
87
|
-
validator = BankAccountNumberValidator::Validator::Pl.new value:
|
99
|
+
validator = BankAccountNumberValidator::Validator::Pl.new value: '83'
|
88
100
|
expect(validator.send(:remainder?)).to be false
|
89
101
|
end
|
90
102
|
|
@@ -94,7 +106,7 @@ describe BankAccountNumberValidator::Validator::Pl do
|
|
94
106
|
allow_any_instance_of(BankAccountNumberValidator::Validator::Pl).to receive(:set_first_to_end)
|
95
107
|
|
96
108
|
expect_any_instance_of(BankAccountNumberValidator::Validator::Pl).to receive(:remainder?)
|
97
|
-
validator = BankAccountNumberValidator::Validator::Pl.new value:
|
109
|
+
validator = BankAccountNumberValidator::Validator::Pl.new value: '123'
|
98
110
|
validator.valid
|
99
111
|
end
|
100
112
|
end
|
@@ -1,28 +1,56 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe BankAccountNumberValidator::Validator do
|
4
|
-
before(:all) { @number = "
|
5
|
-
|
6
|
-
describe 'numbrt_only' do
|
7
|
-
it "should return array" do
|
8
|
-
validator = BankAccountNumberValidator::Validator.new(location: :pl, value: @number)
|
9
|
-
expect(validator.send(:numbrt_only, @number)).to eq [8, 3, 1, 0, 1, 0, 1, 0, 2, 3, 0, 0, 0, 0, 2, 6, 1, 3, 9, 5, 1, 0, 0, 0, 0, 0]
|
10
|
-
end
|
11
|
-
end
|
4
|
+
before(:all) { @number = "83" }
|
12
5
|
|
13
6
|
describe 'location_valid' do
|
14
7
|
it "should call location_valid in initialize" do
|
15
|
-
allow_any_instance_of(BankAccountNumberValidator::Validator).to receive(:
|
8
|
+
allow_any_instance_of(BankAccountNumberValidator::Validator).to receive(:remote_white_space).with(@number).and_return('123')
|
16
9
|
|
17
|
-
expect_any_instance_of(BankAccountNumberValidator::Validator).to receive(:location_valid).with(:pl
|
18
|
-
BankAccountNumberValidator::Validator.new(location: :pl, value: @number)
|
10
|
+
expect_any_instance_of(BankAccountNumberValidator::Validator).to receive(:location_valid).with(:pl)
|
11
|
+
BankAccountNumberValidator::Validator.new(location: :pl, value: @number )
|
19
12
|
end
|
20
13
|
|
21
14
|
it "should call PL validator" do
|
22
|
-
allow_any_instance_of(BankAccountNumberValidator::Validator).to receive(:
|
15
|
+
allow_any_instance_of(BankAccountNumberValidator::Validator).to receive(:remote_white_space).with(@number).and_return('123')
|
23
16
|
|
24
|
-
expect(BankAccountNumberValidator::Validator::Pl).to receive(:new).with(value:
|
17
|
+
expect(BankAccountNumberValidator::Validator::Pl).to receive(:new).with(value: '123')
|
25
18
|
BankAccountNumberValidator::Validator.new(location: :pl, value: @number)
|
26
19
|
end
|
27
20
|
end
|
21
|
+
|
22
|
+
describe 'remote_white_space' do
|
23
|
+
before do
|
24
|
+
allow_any_instance_of(BankAccountNumberValidator::Validator).to receive(:location_valid).with(:pl).and_return(@valid_pl)
|
25
|
+
end
|
26
|
+
|
27
|
+
it do
|
28
|
+
validator = BankAccountNumberValidator::Validator.new(location: :pl, value: @number)
|
29
|
+
expect(validator.send(:remote_white_space, ' 12 23 23 23')).to eq('12232323')
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe 'only_numer?' do
|
34
|
+
|
35
|
+
before (:all) do
|
36
|
+
ValidPL = Struct.new(:valid)
|
37
|
+
@valid_pl = ValidPL.new(true)
|
38
|
+
end
|
39
|
+
|
40
|
+
before do
|
41
|
+
allow_any_instance_of(BankAccountNumberValidator::Validator).to receive(:location_valid).with(:pl).and_return(@valid_pl)
|
42
|
+
end
|
43
|
+
|
44
|
+
it "return false" do
|
45
|
+
allow_any_instance_of(BankAccountNumberValidator::Validator).to receive(:remote_white_space).with(@number).and_return('123a')
|
46
|
+
validator = BankAccountNumberValidator::Validator.new(location: :pl, value: @number)
|
47
|
+
expect(validator.valid).to be false
|
48
|
+
end
|
49
|
+
|
50
|
+
it "return true" do
|
51
|
+
allow_any_instance_of(BankAccountNumberValidator::Validator).to receive(:remote_white_space).with(@number).and_return('123')
|
52
|
+
validator = BankAccountNumberValidator::Validator.new(location: :pl, value: @number)
|
53
|
+
expect(validator.valid).to be true
|
54
|
+
end
|
55
|
+
end
|
28
56
|
end
|
@@ -6,12 +6,12 @@ describe BankAccountNumberValidator do
|
|
6
6
|
describe "valid is false" do
|
7
7
|
|
8
8
|
it "number is incorrect" do
|
9
|
-
dummy_class = DummyClass.new number: '
|
9
|
+
dummy_class = DummyClass.new number: '1234567890123456789012345444444535353453'
|
10
10
|
expect(dummy_class.valid?).to be false
|
11
11
|
end
|
12
12
|
|
13
13
|
it "should return errors" do
|
14
|
-
dummy_class = DummyClass.new number: '
|
14
|
+
dummy_class = DummyClass.new number: '83 1010 1023 0000 2613 9510 0001'
|
15
15
|
dummy_class.valid?
|
16
16
|
expect(dummy_class.errors[:number]).to_not be_empty
|
17
17
|
end
|
@@ -20,12 +20,12 @@ describe BankAccountNumberValidator do
|
|
20
20
|
describe "valid is true" do
|
21
21
|
|
22
22
|
it "number is correct" do
|
23
|
-
dummy_class = DummyClass.new number: '
|
23
|
+
dummy_class = DummyClass.new number: '83 1010 1023 0000 2613 9510 0000'
|
24
24
|
expect(dummy_class.valid?).to be true
|
25
25
|
end
|
26
26
|
|
27
27
|
it "should not return errors" do
|
28
|
-
dummy_class = DummyClass.new number: '
|
28
|
+
dummy_class = DummyClass.new number: '83 1010 1023 0000 2613 9510 0000'
|
29
29
|
dummy_class.valid?
|
30
30
|
expect(dummy_class.errors[:number]).to be_empty
|
31
31
|
end
|