business-br 0.1.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/business-br/cep.rb +6 -4
- data/lib/business-br/cpf.rb +58 -0
- data/lib/business-br/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 969f4b8d75e8f1779600fcf28adf3dab1db74897
|
4
|
+
data.tar.gz: 56a29ba82806f19125bdc828324576fb40b0ad0e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d0b7623643f585d2f46f3390021c19e04308f644e3ad4dc6de7e68ecf0d69df2a804edeedaf2eb626d85c9c49c854c261a5d50878f41d7e2454801a07f53ef95
|
7
|
+
data.tar.gz: 7d87b7e37c235efbacef8a7ebbbe320d9a6e553aa9427aa11dd3632095fc9c1822fb9100fd39dbde7b6d61501fc3b77aadc92adfa8fd39549fa09b17ffc7d342
|
data/lib/business-br/cep.rb
CHANGED
@@ -33,7 +33,11 @@ module Business::BR
|
|
33
33
|
|
34
34
|
|
35
35
|
def normalize(cep)
|
36
|
-
|
36
|
+
"#{$1}#{$2}" if cep =~ /^(\d{5})-?(\d{3})$/
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
def format(cep)
|
37
41
|
"#{$1}-#{$2}" if cep =~ /^(\d{5})-?(\d{3})$/
|
38
42
|
end
|
39
43
|
|
@@ -45,10 +49,8 @@ module Business::BR
|
|
45
49
|
|
46
50
|
|
47
51
|
def type(cep)
|
48
|
-
raise Exception.new('This cep is not valid') unless valid?(cep)
|
49
|
-
|
50
52
|
cep = normalize(cep)
|
51
|
-
suffix = cep
|
53
|
+
suffix = cep.slice(5, 3).to_i
|
52
54
|
case
|
53
55
|
when suffix < 900 then 'LOGRADOURO'
|
54
56
|
when suffix < 960 then 'ESPECIAL'
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module Business::BR
|
2
|
+
class CPF
|
3
|
+
|
4
|
+
@@black_list = %w[
|
5
|
+
00000000000
|
6
|
+
11111111111
|
7
|
+
22222222222
|
8
|
+
33333333333
|
9
|
+
44444444444
|
10
|
+
55555555555
|
11
|
+
66666666666
|
12
|
+
77777777777
|
13
|
+
88888888888
|
14
|
+
99999999999
|
15
|
+
]
|
16
|
+
|
17
|
+
def validate(cpf)
|
18
|
+
return false unless cpf
|
19
|
+
return false unless cpf.length == 11 || cpf.length == 14
|
20
|
+
return false unless cpf =~ /^\d{3}\.?\d{3}\.?\d{3}-?\d{2}$/
|
21
|
+
|
22
|
+
cpf = normalize(cpf)
|
23
|
+
return false unless not @@black_list.include? cpf
|
24
|
+
|
25
|
+
first_num = 0
|
26
|
+
second_num = 0
|
27
|
+
|
28
|
+
9.times do |i|
|
29
|
+
first_num += (10 - i) * cpf[i].to_i
|
30
|
+
end
|
31
|
+
|
32
|
+
10.times do |i|
|
33
|
+
second_num += (11 - i) * cpf[i].to_i
|
34
|
+
end
|
35
|
+
|
36
|
+
first_num = (first_num * 10) % 11
|
37
|
+
first_num = 0 if first_num == 10
|
38
|
+
|
39
|
+
second_num = (second_num * 10) % 11
|
40
|
+
second_num = 0 if second_num == 10
|
41
|
+
|
42
|
+
return false unless "#{first_num}#{second_num}" == cpf[9..10]
|
43
|
+
|
44
|
+
true
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
def normalize(cpf)
|
49
|
+
"#{$1}#{$2}#{$3}#{$4}" if cpf =~ /^(\d{3})\.?(\d{3})\.?(\d{3})-?(\d{2})$/
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
def format(cpf)
|
54
|
+
"#{$1}.#{$2}.#{$3}-#{$4}" if cpf =~ /^(\d{3})\.?(\d{3})\.?(\d{3})-?(\d{2})$/
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
end
|
data/lib/business-br/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: business-br
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Vinciguerra
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-09-
|
11
|
+
date: 2016-09-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -68,6 +68,7 @@ files:
|
|
68
68
|
- business-br.gemspec
|
69
69
|
- lib/business-br.rb
|
70
70
|
- lib/business-br/cep.rb
|
71
|
+
- lib/business-br/cpf.rb
|
71
72
|
- lib/business-br/version.rb
|
72
73
|
homepage: https://github.com/dvinciguerra/business-br
|
73
74
|
licenses: []
|