brid 0.1.0 → 0.1.1
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.
- data/brid.gemspec +2 -2
- data/lib/brid/detector.rb +23 -0
- data/lib/brid/generic_id.rb +2 -0
- data/lib/brid/version.rb +1 -1
- data/lib/brid.rb +1 -1
- data/spec/brid_spec.rb +8 -0
- metadata +8 -5
data/brid.gemspec
CHANGED
@@ -4,8 +4,8 @@ require File.expand_path('../lib/brid/version', __FILE__)
|
|
4
4
|
Gem::Specification.new do |gem|
|
5
5
|
gem.authors = ["Halan Pinheiro"]
|
6
6
|
gem.email = ["halan.pinheiro@gmail.com"]
|
7
|
-
gem.description = %q{Brazilian identifications like CPF, CNPJ,
|
8
|
-
gem.summary = %q{Brazilian identifications like CPF, CNPJ,
|
7
|
+
gem.description = %q{Brazilian identifications like CPF, CNPJ, Titulo de Eleitor}
|
8
|
+
gem.summary = %q{Brazilian identifications like CPF, CNPJ, Titulo de Eleitor}
|
9
9
|
gem.homepage = ""
|
10
10
|
|
11
11
|
gem.files = `git ls-files`.split($\)
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Brid
|
2
|
+
@@detect_between = {
|
3
|
+
:cpf => Brid::CPF,
|
4
|
+
:cnpj => Brid::CNPJ,
|
5
|
+
:titulo_eleitor => Brid::TituloEleitor,
|
6
|
+
:pis => Brid::PIS
|
7
|
+
}
|
8
|
+
|
9
|
+
def self.detect number, between = [:cpf, :cnpj, :titulo_eleitor, :pis]
|
10
|
+
id = [*between].each do |class_symbol|
|
11
|
+
break unless class_symbol
|
12
|
+
|
13
|
+
class_constant = @@detect_between[class_symbol]
|
14
|
+
begin
|
15
|
+
_number = class_constant.new number
|
16
|
+
break _number if _number and _number.valid?
|
17
|
+
rescue ArgumentError
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
id if id.kind_of? GenericID
|
22
|
+
end
|
23
|
+
end
|
data/lib/brid/generic_id.rb
CHANGED
data/lib/brid/version.rb
CHANGED
data/lib/brid.rb
CHANGED
data/spec/brid_spec.rb
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'lib', 'brid.rb')
|
2
|
+
|
3
|
+
describe Brid do
|
4
|
+
it { Brid.detect('009.147.274-19').should be_kind_of(CPF) }
|
5
|
+
it { Brid.detect('18781203000128').should be_kind_of(CNPJ) }
|
6
|
+
it { Brid.detect('009.147.274-19', nil).should be_nil }
|
7
|
+
|
8
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: brid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Halan Pinheiro
|
@@ -18,7 +18,7 @@ cert_chain: []
|
|
18
18
|
date: 2012-07-18 00:00:00 Z
|
19
19
|
dependencies: []
|
20
20
|
|
21
|
-
description:
|
21
|
+
description: Brazilian identifications like CPF, CNPJ, Titulo de Eleitor
|
22
22
|
email:
|
23
23
|
- halan.pinheiro@gmail.com
|
24
24
|
executables: []
|
@@ -36,6 +36,7 @@ files:
|
|
36
36
|
- Rakefile
|
37
37
|
- brid.gemspec
|
38
38
|
- lib/brid.rb
|
39
|
+
- lib/brid/detector.rb
|
39
40
|
- lib/brid/generic_id.rb
|
40
41
|
- lib/brid/ids/cnpj.rb
|
41
42
|
- lib/brid/ids/cpf.rb
|
@@ -43,6 +44,7 @@ files:
|
|
43
44
|
- lib/brid/ids/titulo_eleitor.rb
|
44
45
|
- lib/brid/mod11.rb
|
45
46
|
- lib/brid/version.rb
|
47
|
+
- spec/brid_spec.rb
|
46
48
|
- spec/cnpj_spec.rb
|
47
49
|
- spec/cpf_spec.rb
|
48
50
|
- spec/generic_id_spec.rb
|
@@ -81,8 +83,9 @@ rubyforge_project:
|
|
81
83
|
rubygems_version: 1.8.24
|
82
84
|
signing_key:
|
83
85
|
specification_version: 3
|
84
|
-
summary:
|
86
|
+
summary: Brazilian identifications like CPF, CNPJ, Titulo de Eleitor
|
85
87
|
test_files:
|
88
|
+
- spec/brid_spec.rb
|
86
89
|
- spec/cnpj_spec.rb
|
87
90
|
- spec/cpf_spec.rb
|
88
91
|
- spec/generic_id_spec.rb
|