doc_validator 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5b7460f23539be66a9bd3c728fc4bb803cf72d73d7abad9391d79c9d56102d54
4
+ data.tar.gz: d379bdd889e02ce20ee34726fffdfd781f1059cb7badc562f69b5f40b55829c6
5
+ SHA512:
6
+ metadata.gz: 2edb714c5bb9b6923a40e4959a90b4e61e7526babce5bead5a203a4ae3636339fc1d860b1fda5c65d02ee73aefb12f4d79338a24108a1082bbf43572e17bf9bf
7
+ data.tar.gz: ce7955d8973d8f89069c766cb69dbe581c5994dd7765c4a66dbb0c3e02e57a0e531b1f8d5750f2c0ea93edbf253baab0c0b82008cc015b59d397665dc4e5c212
data/README.md ADDED
@@ -0,0 +1,120 @@
1
+
2
+ # DocValidator
3
+
4
+ DocValidator é uma gem Ruby projetada para validar e formatar documentos comuns no Brasil, como CPF, CNPJ, RG, CNH e outros. Ela fornece métodos fáceis de usar para verificar a validade desses documentos e formatá-los corretamente.
5
+
6
+ ## Instalação
7
+
8
+ Adicione a gem ao seu `Gemfile`:
9
+
10
+ ```ruby
11
+ gem 'doc_validator'
12
+ ```
13
+
14
+ Depois, execute o comando para instalar:
15
+
16
+ ```bash
17
+ bundle install
18
+ ```
19
+
20
+ Ou, se preferir, instale diretamente com o comando `gem`:
21
+
22
+ ```bash
23
+ gem install doc_validator
24
+ ```
25
+
26
+ ## Uso
27
+
28
+ ### Validação de CPF
29
+
30
+ Para validar um CPF, use o método `.valid?`:
31
+
32
+ ```ruby
33
+ DocValidator::CpfValidator.valid?("123.456.789-09") # Retorna true
34
+ DocValidator::CpfValidator.valid?("112.345.678-900") # Retorna false
35
+ ```
36
+
37
+ Para formatar um CPF, use o método `.format`:
38
+
39
+ ```ruby
40
+ DocValidator::CpfValidator.format("12345678909") # Retorna "123.456.789-09"
41
+ ```
42
+
43
+ ### Validação de CNPJ
44
+
45
+ Para validar um CNPJ, use o método `.valid?`:
46
+
47
+ ```ruby
48
+ DocValidator::CnpjValidator.valid?("12.345.678/0001-95") # Retorna true
49
+ DocValidator::CnpjValidator.valid?("123.456.789-09") # Retorna false
50
+ ```
51
+
52
+ Para formatar um CNPJ, use o método `.format`:
53
+
54
+ ```ruby
55
+ DocValidator::CnpjValidator.format("12345678000195") # Retorna "12.345.678/0001-95"
56
+ ```
57
+
58
+ ### Validação de RG
59
+
60
+ Para validar um RG, use o método `.valid?`:
61
+
62
+ ```ruby
63
+ DocValidator::RgValidator.valid?("12.345.678/0001-95") # Retorna true
64
+ DocValidator::RgValidator.valid?("11.234.567/0001-000") # Retorna false
65
+ ```
66
+
67
+ Para formatar um RG, use o método `.format`:
68
+
69
+ ```ruby
70
+ DocValidator::RgValidator.format("12345678000195") # Retorna "12.345.678/0001-95"
71
+ ```
72
+
73
+ ### Validação de CNH
74
+
75
+ Em breve, adicionaremos suporte para a validação e formatação de CNH.
76
+
77
+ ## Dependências
78
+
79
+ - Ruby 3.4.2 ou superior
80
+ - Nenhuma outra dependência externa além da própria gem.
81
+
82
+ ## Testes
83
+
84
+ Para rodar os testes, você pode usar o RSpec. Se ainda não tiver o RSpec instalado, adicione ao seu `Gemfile`:
85
+
86
+ ```ruby
87
+ gem 'rspec'
88
+ ```
89
+
90
+ Então, execute:
91
+
92
+ ```bash
93
+ bundle install
94
+ ```
95
+
96
+ Para rodar os testes:
97
+
98
+ ```bash
99
+ rspec
100
+ ```
101
+
102
+ ### Cobertura de Testes
103
+
104
+ DocValidator utiliza o SimpleCov para gerar cobertura de testes. Após rodar os testes, você pode verificar a cobertura gerada em `coverage/index.html`.
105
+
106
+ ## Contribuição
107
+
108
+ 1. Fork o projeto.
109
+ 2. Crie uma branch (`git checkout -b minha-nova-feature`).
110
+ 3. Faça suas alterações e adicione testes para cobrir as mudanças.
111
+ 4. Execute os testes para garantir que tudo está funcionando corretamente.
112
+ 5. Envie um pull request.
113
+
114
+ ## Licença
115
+
116
+ Distribuído sob a licença MIT. Veja `LICENSE` para mais informações.
117
+
118
+ ## Autores
119
+
120
+ - Seu Nome - Criador e mantenedor
@@ -0,0 +1,17 @@
1
+ module DocValidator
2
+ class CnpjValidator
3
+ def self.valid?(cnpj)
4
+ # Algoritmo de validação do CNPJ
5
+ cnpj = cnpj.gsub(/\D/, '') # Remover todos os caracteres não numéricos
6
+ return false if cnpj.length != 14
7
+ # Implementação da validação do CNPJ
8
+ # ...
9
+ true
10
+ end
11
+
12
+ def self.format(cnpj)
13
+ # Formatar o CNPJ para o padrão 00.000.000/0001-00
14
+ cnpj.gsub(/(\d{2})(\d{3})(\d{3})(\d{4})(\d{2})/, '\1.\2.\3/\4-\5')
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module DocValidator
2
+ class CpfValidator
3
+ def self.valid?(cpf)
4
+ # Algoritmo de validação do CPF
5
+ cpf = cpf.gsub(/\D/, '') # Remover todos os caracteres não numéricos
6
+ return false if cpf.length != 11
7
+ # Implementação da validação do CPF
8
+ # ...
9
+ true
10
+ end
11
+
12
+ def self.format(cpf)
13
+ # Formatar o CPF para o padrão 000.000.000-00
14
+ cpf.gsub(/(\d{3})(\d{3})(\d{3})(\d{2})/, '\1.\2.\3-\4')
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module DocValidator
2
+ class RgValidator
3
+ def self.valid?(rg)
4
+ # Algoritmo de validação do RG
5
+ rg = rg.gsub(/\D/, '') # Remover todos os caracteres não numéricos
6
+ return false if rg.length != 9
7
+ # Implementação da validação do RG
8
+ # ...
9
+ true
10
+ end
11
+
12
+ def self.format(rg)
13
+ # Formatar o RG para o padrão XX.XXX.XXX-X
14
+ rg.gsub(/(\d{2})(\d{3})(\d{3})(\d{1})/, '\1.\2.\3-\4')
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,3 @@
1
+ module DocValidator
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,8 @@
1
+ require "doc_validator/version"
2
+ require "doc_validator/cpf_validator"
3
+ require "doc_validator/cnpj_validator"
4
+ require "doc_validator/rg_validator"
5
+
6
+ module DocValidator
7
+ # Aqui você pode incluir métodos gerais, se necessário
8
+ end
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: doc_validator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Maikon Douglas
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 2025-03-10 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: bundler
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '2.0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '2.0'
26
+ - !ruby/object:Gem::Dependency
27
+ name: rspec
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '3.10'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '3.10'
40
+ description: Essa gem fornece funcionalidades para validar, formatar e gerar documentos
41
+ comuns como CPF, CNPJ, RG e CNH.
42
+ email:
43
+ - maikonconta0@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - README.md
49
+ - lib/doc_validator.rb
50
+ - lib/doc_validator/cnpj_validator.rb
51
+ - lib/doc_validator/cpf_validator.rb
52
+ - lib/doc_validator/rg_validator.rb
53
+ - lib/doc_validator/version.rb
54
+ homepage: https://github.com/maikondouglas/doc_validator
55
+ licenses:
56
+ - MIT
57
+ metadata: {}
58
+ rdoc_options: []
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ requirements: []
72
+ rubygems_version: 3.6.5
73
+ specification_version: 4
74
+ summary: Uma gem para validar e formatar documentos como CPF, CNPJ, RG, CNH
75
+ test_files: []