banking_data_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 +8 -8
- data/README.md +25 -1
- data/lib/banking_data_validator/bank/base.rb +7 -1
- data/lib/banking_data_validator/version.rb +1 -1
- data/spec/banking_data_validator/bank/bradesco_spec.rb +3 -3
- data/spec/banking_data_validator/bank/brasil_spec.rb +1 -1
- data/spec/banking_data_validator/bank/caixa_spec.rb +1 -1
- data/spec/banking_data_validator/bank/hsbc_spec.rb +2 -2
- data/spec/banking_data_validator/bank/itau_spec.rb +1 -1
- data/spec/banking_data_validator/bank/santander_spec.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YzhmZmVjY2U1MzlhODM5NDFhNmFhYzY3NTMxM2M0NDgxMGYwZmUzMQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZGU2NzNhY2NmZWZjYTc3MjRkYTFmYzlhYmUyMjQ2YmE3ZWY4NWViOA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZTdlNThhZDE3MTMyZGZkMjc5ZTM5OTI0ZGI0MzBmNWVjZDI2ZjJjZjdhODMw
|
10
|
+
MjcxMjgxNmNiMWE1MzJhZmRiY2E5OWRkMjZmNTFhZTdmNjgxNWJlM2Q4MGFj
|
11
|
+
MDUwZmMyYWE5ZTAwMGVkNjRlZjE1NjRjZjVjZWUzZDk0NDQ3Y2E=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YzdjZTA4OTU3NzZjNzEyYjcyMGI3MzZiMDViNGY1MTgwNDQxY2MyNTQ5YjQx
|
14
|
+
MTk1ZWM2ZGFhMjE1M2Y1ZDg2Yjk4YTlhYzBkMTNiOGFlNjM5M2Y1MTE1NTk3
|
15
|
+
NjVjMWI1OGE4YTYyM2E5NzE0YjFjMmRmZTA4MzRhY2VlOWI2ZTQ=
|
data/README.md
CHANGED
@@ -27,7 +27,31 @@ Or install it yourself as:
|
|
27
27
|
|
28
28
|
## Usage
|
29
29
|
|
30
|
-
|
30
|
+
Just call `validates_with BankingDataValidator::Validator`.
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
class Payment
|
34
|
+
# include ActiveModel::Model
|
35
|
+
# attr_accessor :bank_number, :branch_number, :account_number, :account_digit
|
36
|
+
|
37
|
+
validates_with BankingDataValidator::Validator
|
38
|
+
end
|
39
|
+
```
|
40
|
+
|
41
|
+
But if your attribute names are different of our default names you can pass your custom names.
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
class CustomPayment
|
45
|
+
# include ActiveModel::Model
|
46
|
+
# attr_accessor :c_bank, :c_branch, :c_account, :c_digit
|
47
|
+
|
48
|
+
validates_with BankingDataValidator::Validator,
|
49
|
+
bank_number: :c_bank,
|
50
|
+
branch_number: :c_branch,
|
51
|
+
account_number: :c_account,
|
52
|
+
account_digit: :c_digit
|
53
|
+
end
|
54
|
+
```
|
31
55
|
|
32
56
|
## Contributing
|
33
57
|
|
@@ -6,7 +6,9 @@ module BankingDataValidator
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def initialize(branch, account_number, account_digit)
|
9
|
-
@branch
|
9
|
+
@branch = padding_with_zeros(branch, 4)
|
10
|
+
@account_number = padding_with_zeros(account_number)
|
11
|
+
@account_digit = padding_with_zeros(account_digit)
|
10
12
|
end
|
11
13
|
|
12
14
|
def valid_account?
|
@@ -15,6 +17,10 @@ module BankingDataValidator
|
|
15
17
|
|
16
18
|
private
|
17
19
|
|
20
|
+
def padding_with_zeros(number, padding = 0)
|
21
|
+
number.to_s.rjust(padding, "0")
|
22
|
+
end
|
23
|
+
|
18
24
|
def multiply_factors
|
19
25
|
digits.reverse.inject(0) do |total, algarism|
|
20
26
|
total + algarism * factors.next
|
@@ -5,12 +5,12 @@ module BankingDataValidator
|
|
5
5
|
RSpec.describe Bradesco do
|
6
6
|
describe "#valid_account?" do
|
7
7
|
it "returns true when is given an account_number with a valid digit" do
|
8
|
-
expect(Bradesco.valid_account?(nil,
|
9
|
-
expect(Bradesco.valid_account?(nil,
|
8
|
+
expect(Bradesco.valid_account?(nil, 238069, "2")).to eq(true)
|
9
|
+
expect(Bradesco.valid_account?(nil, 160000, "1")).to eq(true)
|
10
10
|
expect(Bradesco.valid_account?(nil, "87087", "0")).to eq(true)
|
11
11
|
expect(Bradesco.valid_account?(nil, "71000", "8")).to eq(true)
|
12
12
|
expect(Bradesco.valid_account?(nil, "3257", "3")).to eq(true)
|
13
|
-
expect(Bradesco.valid_account?(nil,
|
13
|
+
expect(Bradesco.valid_account?(nil, 121, "p")).to eq(true)
|
14
14
|
end
|
15
15
|
|
16
16
|
it "returns false when is given an account_number with an invalid digit" do
|
@@ -7,7 +7,7 @@ module BankingDataValidator
|
|
7
7
|
it "returns true when is given an account_number with a valid digit" do
|
8
8
|
expect(Brasil.valid_account?(nil, "65005", "6")).to eq(true)
|
9
9
|
expect(Brasil.valid_account?(nil, "22029", "9")).to eq(true)
|
10
|
-
expect(Brasil.valid_account?(nil,
|
10
|
+
expect(Brasil.valid_account?(nil, 70000, "2")).to eq(true)
|
11
11
|
expect(Brasil.valid_account?(nil, "7107", "2")).to eq(true)
|
12
12
|
expect(Brasil.valid_account?(nil, "80000", "7")).to eq(true)
|
13
13
|
expect(Brasil.valid_account?(nil, "8354", "2")).to eq(true)
|
@@ -7,7 +7,7 @@ module BankingDataValidator
|
|
7
7
|
it "returns true when is given an account_number with a valid digit" do
|
8
8
|
expect(Caixa.valid_account?("2004", "00100000448", "6")).to eq(true)
|
9
9
|
expect(Caixa.valid_account?("1314", "01300169300", "1")).to eq(true)
|
10
|
-
expect(Caixa.valid_account?(
|
10
|
+
expect(Caixa.valid_account?(268, "00100030339", "5")).to eq(true)
|
11
11
|
expect(Caixa.valid_account?("3498", "00100021718", "8")).to eq(true)
|
12
12
|
end
|
13
13
|
|
@@ -5,10 +5,10 @@ module BankingDataValidator
|
|
5
5
|
RSpec.describe HSBC do
|
6
6
|
describe "#valid_account?" do
|
7
7
|
it "returns true when is given an account_number with a valid digit" do
|
8
|
-
expect(HSBC.valid_account?(
|
8
|
+
expect(HSBC.valid_account?(7, "853838", "6")).to eq(true)
|
9
9
|
expect(HSBC.valid_account?("1823", "023467", "7")).to eq(true)
|
10
10
|
expect(HSBC.valid_account?("0336", "006625", "3")).to eq(true)
|
11
|
-
expect(HSBC.valid_account?(
|
11
|
+
expect(HSBC.valid_account?(885, "008468", "2")).to eq(true)
|
12
12
|
end
|
13
13
|
|
14
14
|
it "returns false when is given an account_number with an invalid digit" do
|
@@ -5,7 +5,7 @@ module BankingDataValidator
|
|
5
5
|
RSpec.describe Itau do
|
6
6
|
describe "#valid_account?" do
|
7
7
|
it "returns true when is given an account_number with a valid digit" do
|
8
|
-
expect(Itau.valid_account?(
|
8
|
+
expect(Itau.valid_account?(262, "42602", "6")).to eq(true)
|
9
9
|
expect(Itau.valid_account?("1517", "15667", "3")).to eq(true)
|
10
10
|
expect(Itau.valid_account?("2545", "02366", "1")).to eq(true)
|
11
11
|
expect(Itau.valid_account?("8252", "09881", "2")).to eq(true)
|
@@ -5,7 +5,7 @@ module BankingDataValidator
|
|
5
5
|
RSpec.describe Santander do
|
6
6
|
describe "#valid_account?" do
|
7
7
|
it "returns true when is given an account_number with a valid digit" do
|
8
|
-
expect(Santander.valid_account?(
|
8
|
+
expect(Santander.valid_account?(189, "01017417", "9")).to eq(true)
|
9
9
|
expect(Santander.valid_account?("3140", "13000470", "9")).to eq(true)
|
10
10
|
expect(Santander.valid_account?("1227", "43000005", "2")).to eq(true)
|
11
11
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: banking_data_validator
|
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
|
- Americo Duarte
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|