cpf_cnpj 0.2.1 → 0.3.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.
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cpf_cnpj
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nando Vieira
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-07 00:00:00.000000000 Z
11
+ date: 2016-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rspec
14
+ name: pry-meta
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
@@ -25,7 +25,21 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: pry-meta
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest-utils
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
45
  - - ">="
@@ -49,9 +63,8 @@ extensions: []
49
63
  extra_rdoc_files: []
50
64
  files:
51
65
  - ".gitignore"
52
- - ".rspec"
66
+ - ".travis.yml"
53
67
  - Gemfile
54
- - Gemfile.lock
55
68
  - LICENSE
56
69
  - README.md
57
70
  - Rakefile
@@ -59,28 +72,25 @@ files:
59
72
  - bin/cpf
60
73
  - cpf_cnpj.gemspec
61
74
  - lib/cnpj.rb
62
- - lib/cnpj/cli.rb
63
75
  - lib/cnpj/formatter.rb
64
- - lib/cnpj/generator.rb
65
76
  - lib/cnpj/verifier_digit.rb
66
77
  - lib/cpf.rb
67
- - lib/cpf/cli.rb
68
78
  - lib/cpf/formatter.rb
69
- - lib/cpf/generator.rb
70
79
  - lib/cpf/verifier_digit.rb
71
80
  - lib/cpf_cnpj.rb
81
+ - lib/cpf_cnpj/cli.rb
82
+ - lib/cpf_cnpj/generator.rb
72
83
  - lib/cpf_cnpj/version.rb
73
- - spec/cnpj/cli_spec.rb
74
- - spec/cnpj/formatter_spec.rb
75
- - spec/cnpj/generator_spec.rb
76
- - spec/cnpj_spec.rb
77
- - spec/cpf/cli_spec.rb
78
- - spec/cpf/formatter_spec.rb
79
- - spec/cpf/generator_spec.rb
80
- - spec/cpf_spec.rb
81
- - spec/spec_helper.rb
82
- - spec/support/capture_exit.rb
83
- - spec/support/validation_shared.rb
84
+ - test/support/capture_syscall.rb
85
+ - test/test_helper.rb
86
+ - test/unit/cnpj/cli_test.rb
87
+ - test/unit/cnpj/formatter_test.rb
88
+ - test/unit/cnpj/generator_test.rb
89
+ - test/unit/cnpj_test.rb
90
+ - test/unit/cpf/cli_test.rb
91
+ - test/unit/cpf/formatter_test.rb
92
+ - test/unit/cpf/generator_test.rb
93
+ - test/unit/cpf_test.rb
84
94
  homepage:
85
95
  licenses: []
86
96
  metadata: {}
@@ -100,19 +110,18 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
110
  version: '0'
101
111
  requirements: []
102
112
  rubyforge_project:
103
- rubygems_version: 2.2.2
113
+ rubygems_version: 2.5.1
104
114
  signing_key:
105
115
  specification_version: 4
106
116
  summary: Validate, generate and format CPF/CNPJ numbers. Include command-line tools.
107
117
  test_files:
108
- - spec/cnpj/cli_spec.rb
109
- - spec/cnpj/formatter_spec.rb
110
- - spec/cnpj/generator_spec.rb
111
- - spec/cnpj_spec.rb
112
- - spec/cpf/cli_spec.rb
113
- - spec/cpf/formatter_spec.rb
114
- - spec/cpf/generator_spec.rb
115
- - spec/cpf_spec.rb
116
- - spec/spec_helper.rb
117
- - spec/support/capture_exit.rb
118
- - spec/support/validation_shared.rb
118
+ - test/support/capture_syscall.rb
119
+ - test/test_helper.rb
120
+ - test/unit/cnpj/cli_test.rb
121
+ - test/unit/cnpj/formatter_test.rb
122
+ - test/unit/cnpj/generator_test.rb
123
+ - test/unit/cnpj_test.rb
124
+ - test/unit/cpf/cli_test.rb
125
+ - test/unit/cpf/formatter_test.rb
126
+ - test/unit/cpf/generator_test.rb
127
+ - test/unit/cpf_test.rb
data/.rspec DELETED
@@ -1 +0,0 @@
1
- --color
@@ -1,47 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- cpf_cnpj (0.2.1)
5
-
6
- GEM
7
- remote: http://rubygems.org/
8
- specs:
9
- awesome_print (1.2.0)
10
- coderay (1.1.0)
11
- diff-lcs (1.2.5)
12
- method_source (0.8.2)
13
- pry (0.10.1)
14
- coderay (~> 1.1.0)
15
- method_source (~> 0.8.1)
16
- slop (~> 3.4)
17
- pry-meta (0.0.9)
18
- awesome_print
19
- pry
20
- pry-nav
21
- pry-remote
22
- pry-nav (0.2.4)
23
- pry (>= 0.9.10, < 0.11.0)
24
- pry-remote (0.1.8)
25
- pry (~> 0.9)
26
- slop (~> 3.0)
27
- rspec (3.1.0)
28
- rspec-core (~> 3.1.0)
29
- rspec-expectations (~> 3.1.0)
30
- rspec-mocks (~> 3.1.0)
31
- rspec-core (3.1.7)
32
- rspec-support (~> 3.1.0)
33
- rspec-expectations (3.1.2)
34
- diff-lcs (>= 1.2.0, < 2.0)
35
- rspec-support (~> 3.1.0)
36
- rspec-mocks (3.1.3)
37
- rspec-support (~> 3.1.0)
38
- rspec-support (3.1.2)
39
- slop (3.6.0)
40
-
41
- PLATFORMS
42
- ruby
43
-
44
- DEPENDENCIES
45
- cpf_cnpj!
46
- pry-meta
47
- rspec
@@ -1,102 +0,0 @@
1
- class CNPJ
2
- class CLI
3
- attr_accessor :arguments
4
- attr_accessor :stdin
5
- attr_accessor :stdout
6
- attr_accessor :stderr
7
-
8
- def initialize(arguments, stdin, stdout, stderr)
9
- @arguments = arguments
10
- @stdin = stdin
11
- @stdout = stdout
12
- @stderr = stderr
13
- end
14
-
15
- def start
16
- options = {}
17
-
18
- opts.banner = "Usage: cnpj [options] [CNPJ number]"
19
- opts.separator ""
20
- opts.separator "Specific options:"
21
-
22
- opts.on("-c", "--check", "Check if CNPJ is valid") do
23
- options[:check] = true
24
- end
25
-
26
- opts.on("-g", "--generate", "Generate a new CNPJ") do
27
- options[:generate] = true
28
- end
29
-
30
- opts.on("-f", "--format", "Format CNPJ with separators") do
31
- options[:format] = true
32
- end
33
-
34
- opts.on("-s", "--strip", "Remove CNPJ separators") do
35
- options[:strip] = true
36
- end
37
-
38
- opts.on("-v", "--version", "Show version") do
39
- stdout << VERSION
40
- exit
41
- end
42
-
43
- opts.on_tail("-h", "--help", "Show help") do
44
- help
45
- exit
46
- end
47
-
48
- opts.parse!(arguments)
49
- opts.permute!(arguments)
50
-
51
- help and exit(1) if options.empty?
52
- generate(options) if options[:generate]
53
-
54
- cnpj = CNPJ.new(arguments.first || stdin.read)
55
- validate(cnpj)
56
- format(cnpj) if options[:format]
57
- strip(cnpj) if options[:strip]
58
- check(cnpj) if options[:check]
59
- end
60
-
61
- def validate(cnpj)
62
- return if cnpj.valid?
63
- stderr << "Error: Invalid number\n"
64
- exit 1
65
- end
66
-
67
- def check(cnpj)
68
- exit
69
- end
70
-
71
- def generate(options)
72
- cnpj = CNPJ.new(Generator.generate)
73
-
74
- if options[:strip]
75
- stdout << cnpj.stripped
76
- else
77
- stdout << cnpj.formatted
78
- end
79
-
80
- exit
81
- end
82
-
83
- def format(cnpj)
84
- stdout << cnpj.formatted
85
- exit
86
- end
87
-
88
- def strip(cnpj)
89
- stdout << cnpj.stripped
90
- exit
91
- end
92
-
93
- def help
94
- stderr << opts.to_s
95
- exit 1
96
- end
97
-
98
- def opts
99
- @opts ||= OptionParser.new
100
- end
101
- end
102
- end
@@ -1,12 +0,0 @@
1
- class CNPJ
2
- class Generator
3
- NUMBERS = [*0..9].freeze
4
-
5
- def self.generate
6
- numbers = 12.times.map { NUMBERS.sample }
7
- numbers << VerifierDigit.generate(numbers)
8
- numbers << VerifierDigit.generate(numbers)
9
- numbers.join("")
10
- end
11
- end
12
- end
@@ -1,103 +0,0 @@
1
- class CPF
2
- class CLI
3
- attr_accessor :arguments
4
- attr_accessor :stdin
5
- attr_accessor :stdout
6
- attr_accessor :stderr
7
-
8
- def initialize(arguments, stdin, stdout, stderr)
9
- @arguments = arguments
10
- @stdin = stdin
11
- @stdout = stdout
12
- @stderr = stderr
13
- end
14
-
15
- def start
16
- options = {}
17
-
18
- opts.banner = "Usage: cpf [options] [CPF number]"
19
- opts.separator ""
20
- opts.separator "Specific options:"
21
-
22
- opts.on("-c", "--check", "Check if CPF is valid") do
23
- options[:check] = true
24
- end
25
-
26
- opts.on("-g", "--generate", "Generate a new CPF") do
27
- options[:generate] = true
28
- end
29
-
30
- opts.on("-f", "--format", "Format CPF with separators") do
31
- options[:format] = true
32
- end
33
-
34
- opts.on("-s", "--strip", "Remove CPF separators") do
35
- options[:strip] = true
36
- end
37
-
38
- opts.on("-v", "--version", "Show version") do
39
- stdout << VERSION
40
- exit
41
- end
42
-
43
- opts.on_tail("-h", "--help", "Show help") do
44
- help
45
- exit
46
- end
47
-
48
- opts.parse!(arguments)
49
- opts.permute!(arguments)
50
-
51
- help if options.empty?
52
- generate(options) if options[:generate]
53
-
54
- cpf = CPF.new(arguments.first || stdin.read)
55
-
56
- validate(cpf)
57
- format(cpf) if options[:format]
58
- strip(cpf) if options[:strip]
59
- check(cpf) if options[:check]
60
- end
61
-
62
- def validate(cpf)
63
- return if cpf.valid?
64
- stderr << "Error: Invalid number\n"
65
- exit 1
66
- end
67
-
68
- def check(cpf)
69
- exit
70
- end
71
-
72
- def generate(options)
73
- cpf = CPF.new(Generator.generate)
74
-
75
- if options[:strip]
76
- stdout << cpf.stripped
77
- else
78
- stdout << cpf.formatted
79
- end
80
-
81
- exit
82
- end
83
-
84
- def format(cpf)
85
- stdout << cpf.formatted
86
- exit
87
- end
88
-
89
- def strip(cpf)
90
- stdout << cpf.stripped
91
- exit
92
- end
93
-
94
- def help
95
- stderr << opts.to_s
96
- exit 1
97
- end
98
-
99
- def opts
100
- @opts ||= OptionParser.new
101
- end
102
- end
103
- end
@@ -1,12 +0,0 @@
1
- class CPF
2
- class Generator
3
- NUMBERS = [*0..9].freeze
4
-
5
- def self.generate
6
- numbers = 9.times.map { NUMBERS.sample }
7
- numbers << VerifierDigit.generate(numbers)
8
- numbers << VerifierDigit.generate(numbers)
9
- numbers.join("")
10
- end
11
- end
12
- end
@@ -1,119 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe CNPJ::CLI do
4
- let(:stdout) { "" }
5
- let(:stderr) { "" }
6
- let(:stdin) { StringIO.new }
7
-
8
- context "check" do
9
- %w[-c --check].each do |switch|
10
- it "checks if provided number is valid [using #{switch}]" do
11
- capture_exit do
12
- CNPJ::CLI.new([switch, "54550752000155"], stdin, stdout, stderr).start
13
- end
14
-
15
- expect(stdout).to eql("")
16
- end
17
-
18
- it "outputs error message if provided number is invalid [using #{switch}]" do
19
- capture_exit(1) do
20
- CNPJ::CLI.new([switch, "invalid"], stdin, stdout, stderr).start
21
- end
22
-
23
- expect(stderr).to include("Error: Invalid number")
24
- end
25
- end
26
- end
27
-
28
- context "help" do
29
- %w[-h --help].each do |switch|
30
- it "outputs help [using #{switch}]" do
31
- capture_exit(1) do
32
- CNPJ::CLI.new([switch], stdin, stdout, stderr).start
33
- end
34
-
35
- expect(stderr).to include("Usage: cnpj")
36
- end
37
- end
38
-
39
- it "outputs help on tail" do
40
- capture_exit(1) do
41
- CNPJ::CLI.new([], stdin, stdout, stderr).start
42
- end
43
-
44
- expect(stderr).to include("Usage: cnpj")
45
- end
46
- end
47
-
48
- context "version" do
49
- %w[-v --version].each do |switch|
50
- it "outputs version [using #{switch}]" do
51
- capture_exit do
52
- CNPJ::CLI.new([switch], stdin, stdout, stderr).start
53
- end
54
-
55
- expect(stdout).to include(CNPJ::VERSION.to_s)
56
- end
57
- end
58
- end
59
-
60
- context "generate" do
61
- %w[-g --generate].each do |switch|
62
- it "generates number [using #{switch}]" do
63
- capture_exit do
64
- CNPJ::CLI.new([switch], stdin, stdout, stderr).start
65
- end
66
-
67
- expect(stdout).to match(CNPJ::REGEX)
68
- end
69
- end
70
-
71
- it "generates stripped number" do
72
- capture_exit do
73
- CNPJ::CLI.new(["-gs"], stdin, stdout, stderr).start
74
- end
75
-
76
- expect(stdout).to match(/\A\d{14}\Z/)
77
- end
78
- end
79
-
80
- context "format" do
81
- %w[-f --format].each do |switch|
82
- it "formats argument [using #{switch}]" do
83
- capture_exit do
84
- CNPJ::CLI.new([switch, "54550752000155"], stdin, stdout, stderr).start
85
- end
86
-
87
- expect(stdout).to include("54.550.752/0001-55")
88
- end
89
- end
90
-
91
- it "formats argument using stdin" do
92
- stdin = StringIO.new("54550752000155")
93
-
94
- capture_exit do
95
- CNPJ::CLI.new(["--format"], stdin, stdout, stderr).start
96
- end
97
-
98
- expect(stdout).to include("54.550.752/0001-55")
99
- end
100
-
101
- let(:switch) { "--format" }
102
- it_behaves_like "validation"
103
- end
104
-
105
- context "strip" do
106
- %w[-s --strip].each do |switch|
107
- it "strips argument [using #{switch}]" do
108
- capture_exit do
109
- CNPJ::CLI.new([switch, "54.550.752/0001-55"], stdin, stdout, stderr).start
110
- end
111
-
112
- expect(stdout).to include("54550752000155")
113
- end
114
- end
115
-
116
- let(:switch) { "--strip" }
117
- it_behaves_like "validation"
118
- end
119
- end