doc_validator 1.1.4 → 1.2.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 +4 -4
- data/README.md +20 -2
- data/lib/doc_validator/cnpj.rb +9 -5
- data/lib/doc_validator/cpf.rb +9 -5
- data/lib/doc_validator/rg.rb +9 -5
- data/lib/doc_validator/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 00630e4c82c7cc29f4681fb3e379717fc17039e02328bd6f49b8a5b21aacc70f
|
4
|
+
data.tar.gz: 3a29a7c36dc0ded72966bfa6c8294c10be7588c8a5f9a7de897b24a30b0196b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bec6ffda79e157eaa2eb3165e88599c6ace39989c88ddce1742ca92292f492144a94b31573963ec2a04516230a6983fbd1b88fb42942cb11fe1759ff6a132d3c
|
7
|
+
data.tar.gz: 68e020b8194848cd32fc53a0c865533af46bd3c334608f1e43feaa5bb60d0c33f2fde7bd51c2a6e986bbddad76ba8efbff7d71450605ee63b2ace3ce2dbe386e
|
data/README.md
CHANGED
@@ -40,6 +40,12 @@ Para formatar um CPF, use o método `.format`:
|
|
40
40
|
DocValidator::Cpf.format("12345678909") # Retorna "123.456.789-09"
|
41
41
|
```
|
42
42
|
|
43
|
+
Para máscara um CNPJ, use o método `.mask`:
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
DocValidator::Cnpj.mask("12345678909") # Retorna "***.456.789-**"
|
47
|
+
```
|
48
|
+
|
43
49
|
### Validação de CNPJ
|
44
50
|
|
45
51
|
Para validar um CNPJ, use o método `.valid?`:
|
@@ -55,19 +61,31 @@ Para formatar um CNPJ, use o método `.format`:
|
|
55
61
|
DocValidator::Cnpj.format("12345678000195") # Retorna "12.345.678/0001-95"
|
56
62
|
```
|
57
63
|
|
64
|
+
Para máscara um CNPJ, use o método `.mask`:
|
65
|
+
|
66
|
+
```ruby
|
67
|
+
DocValidator::Cnpj.mask("12345678000195") # Retorna "**.*345.678/0001-**"
|
68
|
+
```
|
69
|
+
|
58
70
|
### Validação de RG
|
59
71
|
|
60
72
|
Para validar um RG, use o método `.valid?`:
|
61
73
|
|
62
74
|
```ruby
|
63
|
-
DocValidator::Rg.valid?("12.345.678
|
75
|
+
DocValidator::Rg.valid?("12.345.678-9") # Retorna true
|
64
76
|
DocValidator::Rg.valid?("11.234.567/0001-000") # Retorna false
|
65
77
|
```
|
66
78
|
|
67
79
|
Para formatar um RG, use o método `.format`:
|
68
80
|
|
69
81
|
```ruby
|
70
|
-
DocValidator::Rg.format("
|
82
|
+
DocValidator::Rg.format("123456789") # Retorna "12.345.678-9"
|
83
|
+
```
|
84
|
+
|
85
|
+
Para máscara um RG, use o método `.mask`:
|
86
|
+
|
87
|
+
```ruby
|
88
|
+
DocValidator::Rg.mask("123456789") # Retorna "***.345.678-*"
|
71
89
|
```
|
72
90
|
|
73
91
|
### Validação de CNH
|
data/lib/doc_validator/cnpj.rb
CHANGED
@@ -1,17 +1,21 @@
|
|
1
1
|
module DocValidator
|
2
2
|
class Cnpj
|
3
3
|
def self.valid?(cnpj)
|
4
|
-
|
5
|
-
cnpj = cnpj.gsub(/\D/, '') # Remover todos os caracteres não numéricos
|
4
|
+
cnpj = cnpj.gsub(/\D/, '')
|
6
5
|
return false if cnpj.length != 14
|
7
|
-
|
8
|
-
# ...
|
6
|
+
|
9
7
|
true
|
10
8
|
end
|
11
9
|
|
12
10
|
def self.format(cnpj)
|
13
|
-
# Formatar o CNPJ para o padrão 00.000.000/0001-00
|
14
11
|
cnpj.gsub(/(\d{2})(\d{3})(\d{3})(\d{4})(\d{2})/, '\1.\2.\3/\4-\5')
|
15
12
|
end
|
13
|
+
|
14
|
+
def self.mask(cnpj)
|
15
|
+
cnpj = cnpj.gsub(/\D/, '')
|
16
|
+
return cnpj unless cnpj.length == 14
|
17
|
+
|
18
|
+
cnpj.gsub(/(\d{2})(\d{3})(\d{3})(\d{4})(\d{2})/, '**.*\2.\3/\4-**')
|
19
|
+
end
|
16
20
|
end
|
17
21
|
end
|
data/lib/doc_validator/cpf.rb
CHANGED
@@ -1,17 +1,21 @@
|
|
1
1
|
module DocValidator
|
2
2
|
class Cpf
|
3
3
|
def self.valid?(cpf)
|
4
|
-
|
5
|
-
cpf = cpf.gsub(/\D/, '') # Remover todos os caracteres não numéricos
|
4
|
+
cpf = cpf.gsub(/\D/, '')
|
6
5
|
return false if cpf.length != 11
|
7
|
-
|
8
|
-
# ...
|
6
|
+
|
9
7
|
true
|
10
8
|
end
|
11
9
|
|
12
10
|
def self.format(cpf)
|
13
|
-
# Formatar o CPF para o padrão 000.000.000-00
|
14
11
|
cpf.gsub(/(\d{3})(\d{3})(\d{3})(\d{2})/, '\1.\2.\3-\4')
|
15
12
|
end
|
13
|
+
|
14
|
+
def self.mask(cpf)
|
15
|
+
cpf = cpf.gsub(/\D/, '')
|
16
|
+
return cpf unless cpf.length == 11
|
17
|
+
|
18
|
+
cpf.gsub(/(\d{3})(\d{3})(\d{3})(\d{2})/, '***.\2.\3-**')
|
19
|
+
end
|
16
20
|
end
|
17
21
|
end
|
data/lib/doc_validator/rg.rb
CHANGED
@@ -1,17 +1,21 @@
|
|
1
1
|
module DocValidator
|
2
2
|
class Rg
|
3
3
|
def self.valid?(rg)
|
4
|
-
|
5
|
-
rg = rg.gsub(/\D/, '') # Remover todos os caracteres não numéricos
|
4
|
+
rg = rg.gsub(/\D/, '')
|
6
5
|
return false if rg.length != 9
|
7
|
-
|
8
|
-
# ...
|
6
|
+
|
9
7
|
true
|
10
8
|
end
|
11
9
|
|
12
10
|
def self.format(rg)
|
13
|
-
# Formatar o RG para o padrão XX.XXX.XXX-X
|
14
11
|
rg.gsub(/(\d{2})(\d{3})(\d{3})(\d{1})/, '\1.\2.\3-\4')
|
15
12
|
end
|
13
|
+
|
14
|
+
def self.mask(rg)
|
15
|
+
rg = rg.gsub(/\D/, '')
|
16
|
+
return rg unless rg.length == 9
|
17
|
+
|
18
|
+
rg.gsub(/(\d{2})(\d{3})(\d{3})(\d{1})/, '***.\2.\3-*')
|
19
|
+
end
|
16
20
|
end
|
17
21
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: doc_validator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Maikon Douglas
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-03-
|
10
|
+
date: 2025-03-31 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: rspec
|
@@ -126,7 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
126
126
|
- !ruby/object:Gem::Version
|
127
127
|
version: '0'
|
128
128
|
requirements: []
|
129
|
-
rubygems_version: 3.6.
|
129
|
+
rubygems_version: 3.6.2
|
130
130
|
specification_version: 4
|
131
131
|
summary: Uma gem para validação e formatação de documentos
|
132
132
|
test_files: []
|