cpf_cnpj 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6fabca5513107302691457cceb9389c53aa7249c
4
+ data.tar.gz: 16d2efbf715673ae2e4f3e640051683893697397
5
+ SHA512:
6
+ metadata.gz: 5ac81c9d850453ca652b1812bb89e4c582ca0d0257e19bc8fec46d41f7c2a1ad726e760f451f50a4c6c82af0c4ee0219eccb57d515304579f2d113e04cb8ae49
7
+ data.tar.gz: ffea71b4641f2302c8100835e5ce18f8d3bbcdcbd6255cdd64774ad135d3a8a9f5e6488bb6bdb6a4e450cee677efbefc7d45f2001a0e6c2137e5390d8ec5b686
data/.gitignore CHANGED
@@ -3,7 +3,6 @@
3
3
  .bundle
4
4
  .config
5
5
  .yardoc
6
- Gemfile.lock
7
6
  InstalledFiles
8
7
  _yardoc
9
8
  coverage
data/.rspec CHANGED
@@ -1 +1 @@
1
- --color --format documentation
1
+ --color
data/Gemfile CHANGED
@@ -1,2 +1,2 @@
1
- source :rubygems
1
+ source "http://rubygems.org"
2
2
  gemspec
@@ -0,0 +1,43 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ cpf_cnpj (0.2.0)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+ awesome_print (1.2.0)
10
+ coderay (1.0.9)
11
+ diff-lcs (1.2.5)
12
+ method_source (0.8.2)
13
+ pry (0.9.12.2)
14
+ coderay (~> 1.0.5)
15
+ method_source (~> 0.8)
16
+ slop (~> 3.4)
17
+ pry-meta (0.0.5)
18
+ awesome_print
19
+ pry
20
+ pry-nav
21
+ pry-remote
22
+ pry-nav (0.2.3)
23
+ pry (~> 0.9.10)
24
+ pry-remote (0.1.7)
25
+ pry (~> 0.9)
26
+ slop (~> 3.0)
27
+ rspec (2.14.1)
28
+ rspec-core (~> 2.14.0)
29
+ rspec-expectations (~> 2.14.0)
30
+ rspec-mocks (~> 2.14.0)
31
+ rspec-core (2.14.7)
32
+ rspec-expectations (2.14.4)
33
+ diff-lcs (>= 1.1.3, < 2.0)
34
+ rspec-mocks (2.14.4)
35
+ slop (3.4.6)
36
+
37
+ PLATFORMS
38
+ ruby
39
+
40
+ DEPENDENCIES
41
+ cpf_cnpj!
42
+ pry-meta
43
+ rspec
data/README.md CHANGED
@@ -28,6 +28,7 @@ This library has the same API for both CNPJ/CPF, so only one of them is document
28
28
 
29
29
  CPF.valid?(number) # Check if a CPF is valid
30
30
  CPF.generate # Generate a random CPF number
31
+ CPF.generate(true) # Generate a formatted number
31
32
 
32
33
  cpf = CPF.new(number)
33
34
  cpf.formatted # Return formatted CPF (xxx.xxx.xxx-xx)
@@ -15,6 +15,5 @@ Gem::Specification.new do |gem|
15
15
  gem.version = CPF::VERSION
16
16
 
17
17
  gem.add_development_dependency "rspec"
18
- gem.add_development_dependency "pry"
19
- gem.add_development_dependency "awesome_print"
18
+ gem.add_development_dependency "pry-meta"
20
19
  end
@@ -1,8 +1,8 @@
1
1
  class CNPJ
2
- autoload :CLI, "cnpj/cli"
3
- autoload :Formatter, "cnpj/formatter"
4
- autoload :Generator, "cnpj/generator"
5
- autoload :VerifierDigit, "cnpj/verifier_digit"
2
+ require "cnpj/cli"
3
+ require "cnpj/formatter"
4
+ require "cnpj/generator"
5
+ require "cnpj/verifier_digit"
6
6
 
7
7
  attr_reader :number
8
8
 
@@ -25,8 +25,9 @@ class CNPJ
25
25
  new(number).valid?
26
26
  end
27
27
 
28
- def self.generate
29
- Generator.generate
28
+ def self.generate(formatted = false)
29
+ cnpj = new(Generator.generate)
30
+ formatted ? cnpj.formatted : cnpj.stripped
30
31
  end
31
32
 
32
33
  def initialize(number)
data/lib/cpf.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  class CPF
2
- autoload :CLI, "cpf/cli"
3
- autoload :Formatter, "cpf/formatter"
4
- autoload :Generator, "cpf/generator"
5
- autoload :VerifierDigit, "cpf/verifier_digit"
2
+ require "cpf/cli"
3
+ require "cpf/formatter"
4
+ require "cpf/generator"
5
+ require "cpf/verifier_digit"
6
6
 
7
7
  attr_reader :number
8
8
 
@@ -26,8 +26,9 @@ class CPF
26
26
  new(number).valid?
27
27
  end
28
28
 
29
- def self.generate
30
- Generator.generate
29
+ def self.generate(formatted = false)
30
+ cpf = new(Generator.generate)
31
+ formatted ? cpf.formatted : cpf.stripped
31
32
  end
32
33
 
33
34
  def initialize(number)
@@ -1,7 +1,7 @@
1
1
  class CPF
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
4
4
 
5
5
  class CNPJ
6
- VERSION = "0.1.0"
6
+ VERSION = "0.2.0"
7
7
  end
@@ -35,4 +35,12 @@ describe CNPJ do
35
35
  number = "54550[752#0001..$55"
36
36
  expect(CNPJ).to be_valid(number)
37
37
  end
38
+
39
+ it "generates formatted number" do
40
+ expect(CNPJ.generate(true)).to match(%r[\A\d{2}\.\d{3}\.\d{3}/\d{4}-\d{2}\z])
41
+ end
42
+
43
+ it "generates stripped number" do
44
+ expect(CNPJ.generate).to match(/\A\d{14}\z/)
45
+ end
38
46
  end
@@ -47,11 +47,12 @@ describe CPF do
47
47
  expect(cpf.formatted).to eql("295.379.955-93")
48
48
  end
49
49
 
50
- it "generates number" do
51
- CPF::Generator
52
- .should_receive(:generate)
50
+ it "generates formatted number" do
51
+ expect(CPF.generate(true)).to match(/\A\d{3}\.\d{3}\.\d{3}-\d{2}\z/)
52
+ end
53
53
 
54
- CPF.generate
54
+ it "generates stripped number" do
55
+ expect(CPF.generate).to match(/\A\d{11}\z/)
55
56
  end
56
57
 
57
58
  context "memoization" do
metadata CHANGED
@@ -1,62 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cpf_cnpj
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
5
- prerelease:
4
+ version: 0.2.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Nando Vieira
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-08-15 00:00:00.000000000 Z
11
+ date: 2013-11-09 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rspec
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  - !ruby/object:Gem::Dependency
31
- name: pry
28
+ name: pry-meta
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - '>='
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
44
- - !ruby/object:Gem::Version
45
- version: '0'
46
- - !ruby/object:Gem::Dependency
47
- name: awesome_print
48
- requirement: !ruby/object:Gem::Requirement
49
- none: false
50
- requirements:
51
- - - ! '>='
52
- - !ruby/object:Gem::Version
53
- version: '0'
54
- type: :development
55
- prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
- requirements:
59
- - - ! '>='
38
+ - - '>='
60
39
  - !ruby/object:Gem::Version
61
40
  version: '0'
62
41
  description: Validate, generate and format CPF/CNPJ numbers. Include command-line
@@ -72,6 +51,7 @@ files:
72
51
  - .gitignore
73
52
  - .rspec
74
53
  - Gemfile
54
+ - Gemfile.lock
75
55
  - LICENSE
76
56
  - README.md
77
57
  - Rakefile
@@ -103,27 +83,26 @@ files:
103
83
  - spec/support/validation_shared.rb
104
84
  homepage:
105
85
  licenses: []
86
+ metadata: {}
106
87
  post_install_message:
107
88
  rdoc_options: []
108
89
  require_paths:
109
90
  - lib
110
91
  required_ruby_version: !ruby/object:Gem::Requirement
111
- none: false
112
92
  requirements:
113
- - - ! '>='
93
+ - - '>='
114
94
  - !ruby/object:Gem::Version
115
95
  version: '0'
116
96
  required_rubygems_version: !ruby/object:Gem::Requirement
117
- none: false
118
97
  requirements:
119
- - - ! '>='
98
+ - - '>='
120
99
  - !ruby/object:Gem::Version
121
100
  version: '0'
122
101
  requirements: []
123
102
  rubyforge_project:
124
- rubygems_version: 1.8.23
103
+ rubygems_version: 2.0.3
125
104
  signing_key:
126
- specification_version: 3
105
+ specification_version: 4
127
106
  summary: Validate, generate and format CPF/CNPJ numbers. Include command-line tools.
128
107
  test_files:
129
108
  - spec/cnpj/cli_spec.rb
@@ -137,3 +116,4 @@ test_files:
137
116
  - spec/spec_helper.rb
138
117
  - spec/support/capture_exit.rb
139
118
  - spec/support/validation_shared.rb
119
+ has_rdoc: