edacpfbr 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 +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +47 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/edacpfbr.gemspec +32 -0
- data/lib/edacpfbr/version.rb +3 -0
- data/lib/edacpfbr.rb +38 -0
- metadata +145 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b2cf275f400b6b14998a3fb93784552ea97b3912
|
4
|
+
data.tar.gz: 174a94c9abb1b3d817ac9758189181cde19cb197
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3e49a5251ca7ed3b1fa9893ccf89912b7a1b236a61e6dc024ab0bac9da7f4d3cb5a256d80f6d11a398902988f6b9adf79f53678c19b0813907bc7f5d36f6e194
|
7
|
+
data.tar.gz: bb5916bc550c037fd4a95b1f49f040631fac901837196566a857e8f9c328648020f02192ba3bf74ee8c83982a2ec1105a2c35d5262591d06101e719246499b8d
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
edacpfbr
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.3.1
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Ed de Almeida
|
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,47 @@
|
|
1
|
+
# EdaCPFbr
|
2
|
+
|
3
|
+
Esta gema valida CPFs, verificando se os dígitos verificadores estão corretos.
|
4
|
+
|
5
|
+
## Instalação
|
6
|
+
|
7
|
+
Adicione a seguinte linha ao seu Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'edacpfbr'
|
11
|
+
```
|
12
|
+
|
13
|
+
E execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Ou instale você, digitando:
|
18
|
+
|
19
|
+
$ gem install edacpfbr
|
20
|
+
|
21
|
+
## Uso
|
22
|
+
|
23
|
+
Você pode invocar
|
24
|
+
|
25
|
+
EdaCPFbr.validar(cpf)
|
26
|
+
|
27
|
+
onde `cpf` é uma string contendo um CPF completo. O resultado será `true` se o CPF estiver correto, ou seja, se os dois dígitos verificadores estiverem corretos, ou `false` caso contrário.
|
28
|
+
|
29
|
+
|
30
|
+
É possível também validar uma lista de CPFs, passada como uma array, com
|
31
|
+
|
32
|
+
EdaCPFbr.validar_lote(lista)
|
33
|
+
|
34
|
+
Nesse caso a saía será um Hash, com as chaves sendo os CPFs passados e os valores sendo `true` ou `false`, conforme cada CPF seja correto ou não.
|
35
|
+
|
36
|
+
## Desenvolvimento
|
37
|
+
|
38
|
+
Depois de fazer o checkout do repositório, execure `bin/setup` para instalar as dependências. Então execure `rake spec` para rodar todos os testes. Você pode também executar `bin/console` para obter um console iterativo que permitirá fazer experiências com a gema.
|
39
|
+
|
40
|
+
Para instalar esta gema em sua máquina local, execute `bundle exec rake install`.
|
41
|
+
|
42
|
+
Para submeter sua contribuição, faça o push do seu branch com `git pull origin <branch>` e gere o pull request, que será avaliado, sendo o merge resultado da avaliação positiva do código submetido.
|
43
|
+
|
44
|
+
Bugs e pull requests são bemvindos no GitHub em https://github.com/EdDeAlmeidaJr/edacpfbr.
|
45
|
+
|
46
|
+
Esta gema está disponível nos termos da [MIT License](http://opensource.org/licenses/MIT). Isto significa, em resumo, que você pode copiar, modificar e distribuir livremente o código, desde que informe quem é o autor.
|
47
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "edacpfbr"
|
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
data/edacpfbr.gemspec
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'edacpfbr/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "edacpfbr"
|
8
|
+
spec.version = EdaCPFbr::VERSION
|
9
|
+
spec.authors = ["Ed de Almeida"]
|
10
|
+
spec.email = ["edvaldoajunior@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = "Valida CPFs e gera lotes de CPFs aleatórios para teste."
|
13
|
+
spec.description = "Valida CPFs e gera lotes de CPFs aleatórios para teste. Fornece listas de CPFs válidos aleatórios."
|
14
|
+
spec.homepage = "https://github.com/EdDeAlmeidaJr/edacpfbr"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = "bin"
|
21
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.13"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
27
|
+
|
28
|
+
spec.add_runtime_dependency "slop", "~> 4.4"
|
29
|
+
spec.add_runtime_dependency "colorize", "~> 0.8"
|
30
|
+
spec.add_runtime_dependency "json", "~> 2.0"
|
31
|
+
|
32
|
+
end
|
data/lib/edacpfbr.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require "edacpfbr/version"
|
2
|
+
|
3
|
+
module EdaCPFbr
|
4
|
+
|
5
|
+
def self.validar(cpf)
|
6
|
+
return false if cpf.length < 11
|
7
|
+
@cpf = cpf
|
8
|
+
@first_block = @cpf[0..8]
|
9
|
+
@dig1 = @cpf[9]
|
10
|
+
@dig2 = @cpf[10]
|
11
|
+
@second_block = @cpf[1..9]
|
12
|
+
return false if not digito_correto(@first_block,@dig1)
|
13
|
+
return false if not digito_correto(@second_block,@dig2)
|
14
|
+
true
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.validar_lote(lote)
|
18
|
+
retorno_lote = Hash.new
|
19
|
+
lote.each{ |cpf| retorno_lote[cpf] = validar(cpf) }
|
20
|
+
retorno_lote
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.digito_correto(bloco,dig)
|
24
|
+
digito(bloco) == dig.to_i
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.digito(bloco)
|
28
|
+
total = 0
|
29
|
+
(1..9).each do |i|
|
30
|
+
ind = i - 1
|
31
|
+
d = bloco[ind].to_i
|
32
|
+
total += d*i
|
33
|
+
end
|
34
|
+
r = total % 11
|
35
|
+
(r>9) ? 0 : r
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
metadata
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: edacpfbr
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ed de Almeida
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-10-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.13'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.13'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: slop
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '4.4'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '4.4'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: colorize
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.8'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.8'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: json
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '2.0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '2.0'
|
97
|
+
description: Valida CPFs e gera lotes de CPFs aleatórios para teste. Fornece listas
|
98
|
+
de CPFs válidos aleatórios.
|
99
|
+
email:
|
100
|
+
- edvaldoajunior@gmail.com
|
101
|
+
executables:
|
102
|
+
- console
|
103
|
+
- setup
|
104
|
+
extensions: []
|
105
|
+
extra_rdoc_files: []
|
106
|
+
files:
|
107
|
+
- ".gitignore"
|
108
|
+
- ".rspec"
|
109
|
+
- ".ruby-gemset"
|
110
|
+
- ".ruby-version"
|
111
|
+
- ".travis.yml"
|
112
|
+
- Gemfile
|
113
|
+
- LICENSE.txt
|
114
|
+
- README.md
|
115
|
+
- Rakefile
|
116
|
+
- bin/console
|
117
|
+
- bin/setup
|
118
|
+
- edacpfbr.gemspec
|
119
|
+
- lib/edacpfbr.rb
|
120
|
+
- lib/edacpfbr/version.rb
|
121
|
+
homepage: https://github.com/EdDeAlmeidaJr/edacpfbr
|
122
|
+
licenses:
|
123
|
+
- MIT
|
124
|
+
metadata: {}
|
125
|
+
post_install_message:
|
126
|
+
rdoc_options: []
|
127
|
+
require_paths:
|
128
|
+
- lib
|
129
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - ">="
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
requirements: []
|
140
|
+
rubyforge_project:
|
141
|
+
rubygems_version: 2.5.1
|
142
|
+
signing_key:
|
143
|
+
specification_version: 4
|
144
|
+
summary: Valida CPFs e gera lotes de CPFs aleatórios para teste.
|
145
|
+
test_files: []
|