brazilian_documents 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
+ SHA1:
3
+ metadata.gz: ce861f68d1133840aa6d946360599d544ef049df
4
+ data.tar.gz: a1d8b2c6ff7a9a201bc8f0102cae450b3c295bb7
5
+ SHA512:
6
+ metadata.gz: d957127f476c56923c209f4d2068c2552b8b1192aba19ca9ddfb556e3dcd68d93256c6e5756ac8fcc96d08d7044d87338f4622eb733f80b632e7ef38e82e9fa2
7
+ data.tar.gz: ac4d6be54ce6100896ec60bab4ca0ba2833d7e681fd65cebc1aac396d560e6bc4f5dab035d06fbe111763acb90dd88a2320a58e913fe8c37624dc96f29542942
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.0
5
+ before_install: gem install bundler -v 1.12.5
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at rafa_fidelis@yahoo.com.br. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in br_documents.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Rafael Fidelis
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,132 @@
1
+ # BRDocuments
2
+
3
+ Esta gem tem como proposta ser um repositório com os principais validadores de documentos **oficiais do Brasil**.
4
+ Atualmente existem **validadores**(e não geradores) para:
5
+
6
+ * CPF
7
+ * CNPJ
8
+ * RG (Carteira de Identidade) [TODO]
9
+ * Título de Eleitor [TODO]
10
+
11
+ Essa gem é construída em cima da gem [**digit_checksum**](https://github.com/fidelisrafael/digit_checksum), que torna todo o processo muito mais simples e padronizado!
12
+
13
+ ---
14
+
15
+ ## Instalação
16
+
17
+ Adicione no seu Gemfile:
18
+
19
+ ```ruby
20
+ gem 'brazilian_documents'
21
+ ```
22
+
23
+ E execute:
24
+
25
+ $ bundle
26
+
27
+ Ou então instale separadamente (e globalmente) com:
28
+
29
+ $ gem install brazilian_documents
30
+
31
+ ---
32
+
33
+ ## Como usar
34
+
35
+ Entenda que a proposta dessa gem não é gerar número de documentos, somente validar! A ideia é ser pequena e portátil.
36
+
37
+ ### API
38
+
39
+ #### Observação:
40
+
41
+ **TODOS** os documentos tem a mesma **assinatura e interface** de API, sendo assim para manusear tipos diferentes de documento, somente altere o nome da classe para o tipo de documento desejado, que podem ser:
42
+
43
+ ##### `BRDocuments::CPF`
44
+ ##### `BRDocuments::CNPJ`
45
+
46
+ Nos exemplos abaixo, a classe `BRDocuments::CPF` será utilizada para detalhar a **API comum a todos os documentos**, porém lembre-se que você pode usar **qualquer uma** das classes acima listada.
47
+
48
+ ---
49
+
50
+ Você pode usar essa biblioteca para:
51
+
52
+
53
+ #### Validar documento
54
+
55
+ ```ruby
56
+ require 'br_documents'
57
+
58
+ BRDocuments::CPF.valid?(number) # verifica se um CPF é valido
59
+ BRDocuments::CPF.invalid?(number) # verifica se um CPF é inválido
60
+
61
+ # Ex:
62
+
63
+ BRDocuments::CPF.valid?("481.455.512-18") # true
64
+ BRDocuments::CPF.valid?("481.455.512-20") # false
65
+ BRDocuments::CPF.invalid?(48145551220) # true
66
+
67
+ ```
68
+
69
+ #### Calcular dígitos verificadores (DV)
70
+
71
+ ```ruby
72
+ require 'br_documents'
73
+
74
+ # Calcula os dígitos verificadores de um CPF(number deve ser composto de 9 dígitos
75
+ BRDocuments::CPF.calculate_verify_digits(number)
76
+
77
+ # Ex:
78
+
79
+ # Número válido
80
+ BRDocuments::CPF.calculate_verify_digits("481.455.512") # [1, 8]
81
+
82
+ # Número inválido
83
+ BRDocuments::CPF.calculate_verify_digits("481.455.51") # []
84
+ ```
85
+
86
+ #### Normalizar e formatar documento
87
+
88
+ ```ruby
89
+ require 'br_documents'
90
+
91
+ BRDocuments::CPF.pretty_formatted(number) # (XXX.XXX.XXX-XX)
92
+
93
+ # Retorna CPF normalizado como Array ([X,X,X,X,X,X,X,X,X,X,X,X])
94
+ BRDocuments::CPF.normalize_document_number(number)
95
+
96
+ # Retorna CPF normalizado como String (XXXXXXXXXXXX)
97
+ BRDocuments::CPF.normalize_document_number_to_s(number)
98
+
99
+ # Ex:
100
+
101
+ BRDocuments::CPF.pretty_formatted("48145551218") # 481.455.512-18
102
+
103
+ # Normaliza número e retorna como Array: [4, 8, 1, 4, 5, 5, 5, 1, 2, 1, 8]
104
+ BRDocuments::CPF.normalize_document_number("481.455.512-18")
105
+
106
+ BRDocuments::CPF.normalize_document_number_to_s("481.455.512-18") # "48145551218"
107
+
108
+ ```
109
+ ---
110
+
111
+ ## Desenvolvimento
112
+
113
+ Execute `bin/setup` para instalar as dependências to install dependencies. Em seguida execute `rake spec` para executar todos os testes. Você pode também executar `bin/console` para iniciar um shell interativo para seus experimentos
114
+
115
+ Para instalar essa gem localmente em sua máquina, execute `bundle exec rake install`.
116
+
117
+ ---
118
+
119
+ ## Contribua!
120
+
121
+ Você pode enviar bugs reports, pull requests e abrir issues no GitHub: https://github.com/fidelisrafael/br_documents.
122
+ Para entender a arquitetura e padrão de cada arquivo, veja a pasta `lib/br_documents/documents` e leia a documentação da gem [**digit_checksum**](https://github.com/fidelisrafael/digit_checksum).
123
+ Pense em cada documento como um **adapter** criado em cima da API da Gem `DigitCheckSum`.
124
+
125
+ Obrigado!
126
+
127
+ ---
128
+
129
+ ## Licença
130
+
131
+ Essa biblioteca está disponível como projeto open source sob os termos da [Licença MIT](http://opensource.org/licenses/MIT).
132
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "br_documents"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ require 'br_documents/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "brazilian_documents"
9
+ spec.version = BRDocuments::VERSION
10
+ spec.authors = ["Rafael Fidelis"]
11
+ spec.email = ["rafa_fidelis@yahoo.com.br"]
12
+
13
+ spec.summary = %q{Coleção de validadores para documentos brasileiros}
14
+ spec.description = %q{Esta gem implementa vários validadores de documentos oficiais brasileiros, como CPF, CNPJ, RG e Título de Eleitor}
15
+ spec.homepage = "https://github.com/fidelisrafael/brazilian_documents"
16
+ spec.license = "MIT"
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_dependency 'digit_checksum', '~> 0.1.0'
24
+ spec.add_development_dependency "bundler", "~> 1.12"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 3.0"
27
+ end
@@ -0,0 +1,19 @@
1
+ require "digit_checksum"
2
+
3
+ module BRDocuments
4
+ class CNPJ < ::DigitChecksum::BaseDocument
5
+ digits_verify_mask first: %w(5 4 3 2 9 8 7 6 5 4 3 2),
6
+ second: %w(6 5 4 3 2 9 8 7 6 5 4 3 2)
7
+
8
+ # MOD 11
9
+ division_factor_modulo 11
10
+
11
+ # remove any non digit from document number
12
+ clear_number_regexp %r{[^(\d+)]}
13
+
14
+ # match format such as: 99.999.999/9999-99 | 99-999-999/9999-99 | 99999999/999999 | 99999999999999
15
+ valid_format_regexp %r{(\d{2})[-.]?(\d{3})[-.]?(\d{3})[\/]?(\d{4})[-.]?(\d{2})}
16
+
17
+ pretty_format_mask %(%s.%s.%s/%s-%s)
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ require "digit_checksum"
2
+
3
+ module BRDocuments
4
+ class CPF < ::DigitChecksum::BaseDocument
5
+ digits_verify_mask first: %w(10 9 8 7 6 5 4 3 2),
6
+ second: %w(11 10 9 8 7 6 5 4 3 2)
7
+
8
+ # MOD 11
9
+ division_factor_modulo 11
10
+
11
+ # remove any non digit from document number
12
+ clear_number_regexp %r{[^(\d+)]}
13
+
14
+ # match format such as: 999.999.999-99 | 999-999-999-99 | 99999999999
15
+ valid_format_regexp %r{(\d{3})[-.]?(\d{3})[-.]?(\d{3})[-.]?(\d{2})}
16
+
17
+ pretty_format_mask %(%s.%s.%s-%s)
18
+ end
19
+ end
@@ -0,0 +1,3 @@
1
+ module BRDocuments
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,6 @@
1
+ require "br_documents/version"
2
+ require "br_documents/documents/cpf"
3
+ require "br_documents/documents/cnpj"
4
+
5
+ module BRDocuments
6
+ end
@@ -0,0 +1 @@
1
+ require 'br_documents'
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: brazilian_documents
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Rafael Fidelis
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-07-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: digit_checksum
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.1.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.1.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.12'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.12'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description: Esta gem implementa vários validadores de documentos oficiais brasileiros,
70
+ como CPF, CNPJ, RG e Título de Eleitor
71
+ email:
72
+ - rafa_fidelis@yahoo.com.br
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".rspec"
79
+ - ".travis.yml"
80
+ - CODE_OF_CONDUCT.md
81
+ - Gemfile
82
+ - LICENSE.txt
83
+ - README.md
84
+ - Rakefile
85
+ - bin/console
86
+ - bin/setup
87
+ - br_documents.gemspec
88
+ - lib/br_documents.rb
89
+ - lib/br_documents/documents/cnpj.rb
90
+ - lib/br_documents/documents/cpf.rb
91
+ - lib/br_documents/version.rb
92
+ - lib/brazilian_documents.rb
93
+ homepage: https://github.com/fidelisrafael/brazilian_documents
94
+ licenses:
95
+ - MIT
96
+ metadata: {}
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 2.5.1
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: Coleção de validadores para documentos brasileiros
117
+ test_files: []