business-br 0.3.0 → 0.5.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 +4 -4
- data/.travis.yml +22 -0
- data/Gemfile.lock +1 -1
- data/README.md +98 -6
- data/business-br.gemspec +2 -1
- data/lib/business-br/cnpj.rb +45 -0
- data/lib/business-br/version.rb +1 -1
- metadata +7 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8740b2030d689898d957091ef8384399e60ff53a
|
|
4
|
+
data.tar.gz: d2c5e6ca6e66d527e087a11ca5b9a628f21e8b0a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ba74a5f525aa974f14f2b5f85d67ee1b3b42035b2f6e4e9c3b1400f8b0e82986f425e63b17c0494da4deab6c4d93a87da1988e1ebcda8f213ed7895cc7e89e98
|
|
7
|
+
data.tar.gz: 56e82bdc703fd91161181433b423689ececef757dcb9771c030f0e1da371b51888f6ebf2aec19edc7d9224ae6a33202ad0b24c3cff12a6dd884304a12880faf0
|
data/.travis.yml
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
language: ruby
|
|
2
|
+
sudo: false
|
|
3
|
+
|
|
4
|
+
rvm:
|
|
5
|
+
- 2.3.1
|
|
6
|
+
- 2.3.0
|
|
7
|
+
- 2.2.3
|
|
8
|
+
- 2.1.7
|
|
9
|
+
- 2.0.0
|
|
10
|
+
- rbx-2
|
|
11
|
+
- jruby-9.0.5.0
|
|
12
|
+
- jruby-head
|
|
13
|
+
- ruby-head
|
|
14
|
+
|
|
15
|
+
before_install:
|
|
16
|
+
- gem install bundler
|
|
17
|
+
|
|
18
|
+
bundler_args: --without test --jobs 3 --retry 3
|
|
19
|
+
|
|
20
|
+
before_script:
|
|
21
|
+
- bundle update
|
|
22
|
+
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
# Business::
|
|
1
|
+
# Business::BR
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://badge.fury.io/rb/business-br)
|
|
4
|
+
[](https://travis-ci.org/dvinciguerra/business-br)
|
|
5
|
+
[](https://codeclimate.com/github/dvinciguerra/business-br)
|
|
6
|
+
|
|
7
|
+
This gem is a namespace of brazilian documents, ids and currencies validations that provide you simple
|
|
8
|
+
way for make validations in your ruby application.
|
|
4
9
|
|
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
|
6
10
|
|
|
7
11
|
## Installation
|
|
8
12
|
|
|
@@ -22,15 +26,103 @@ Or install it yourself as:
|
|
|
22
26
|
|
|
23
27
|
## Usage
|
|
24
28
|
|
|
25
|
-
|
|
29
|
+
|
|
30
|
+
### For CEP
|
|
31
|
+
|
|
32
|
+
Using class CEP and validations methods:
|
|
33
|
+
|
|
34
|
+
```ruby
|
|
35
|
+
require 'business-br'
|
|
36
|
+
|
|
37
|
+
cep = '13330-000'
|
|
38
|
+
validator = Business::BR::CEP.new
|
|
39
|
+
|
|
40
|
+
# turns from '13330-000' into '13330000'
|
|
41
|
+
cep = validator.normalize(cep)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
# turns from '13330000' into '13330-000'
|
|
45
|
+
cep = validator.format(cep)
|
|
46
|
+
|
|
47
|
+
# getting cep region
|
|
48
|
+
cep_region = validator.region(cep) # => ['SP']
|
|
49
|
+
|
|
50
|
+
# getting cep type
|
|
51
|
+
cep_type = validator.type(cep) # => 'LOGRADOURO'
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
# check if cep is valid
|
|
55
|
+
if validator.valid? '00000asd'
|
|
56
|
+
puts 'This CEP is valid'
|
|
57
|
+
else
|
|
58
|
+
puts 'This CEP is not valid... please try again!'
|
|
59
|
+
end
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
### For CPF
|
|
64
|
+
|
|
65
|
+
Using class CPF and validations methods:
|
|
66
|
+
|
|
67
|
+
```ruby
|
|
68
|
+
require 'business-br'
|
|
69
|
+
|
|
70
|
+
cpf = '111.111.111-11'
|
|
71
|
+
validator = Business::BR::CPF.new
|
|
72
|
+
|
|
73
|
+
# turns from '111.111.111-11' into '11111111111'
|
|
74
|
+
cpf = validator.normalize(cpf)
|
|
75
|
+
|
|
76
|
+
# turns from '11111111111' into '111.111.111-11'
|
|
77
|
+
cpf = validator.format(cpf)
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
# check if cpf is valid
|
|
81
|
+
if validator.valid? '111.111.111-11'
|
|
82
|
+
puts 'This CPF is valid'
|
|
83
|
+
else
|
|
84
|
+
puts 'This CPF is not valid... please try again!'
|
|
85
|
+
end
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
### For CNPJ
|
|
90
|
+
|
|
91
|
+
Using class CNPJ and validations methods:
|
|
92
|
+
|
|
93
|
+
```ruby
|
|
94
|
+
require 'business-br'
|
|
95
|
+
|
|
96
|
+
cnpj = '11.111.111/0001-11'
|
|
97
|
+
validator = Business::BR::CNPJ.new
|
|
98
|
+
|
|
99
|
+
# turns from '11.111.111/0001-11' into '11111111000111'
|
|
100
|
+
cnpj = validator.normalize(cnpj)
|
|
101
|
+
|
|
102
|
+
# turns from '11111111000111' into '11.111.111/0001-11'
|
|
103
|
+
cnpj = validator.format(cnpj)
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
# check if cnpj is valid
|
|
107
|
+
if validator.valid? '11.111.111/0001-11'
|
|
108
|
+
puts 'This CNPJ is valid'
|
|
109
|
+
else
|
|
110
|
+
puts 'This CNPJ is not valid... please try again!'
|
|
111
|
+
end
|
|
112
|
+
```
|
|
113
|
+
|
|
26
114
|
|
|
27
115
|
## Development
|
|
28
116
|
|
|
29
|
-
After checking out the
|
|
117
|
+
After checking out the repon, run bundle install to resolve dependencies and then run `rake spec` to run the tests.
|
|
30
118
|
|
|
31
119
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
32
120
|
|
|
33
121
|
## Contributing
|
|
34
122
|
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
|
123
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/dvinciguerra/business-br.
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
## Authors
|
|
36
127
|
|
|
128
|
+
Daniel Vinciguerra <daniel.vinciguerra@bivee.com.br>
|
data/business-br.gemspec
CHANGED
|
@@ -6,6 +6,7 @@ require 'business-br/version'
|
|
|
6
6
|
|
|
7
7
|
Gem::Specification.new do |spec|
|
|
8
8
|
spec.name = "business-br"
|
|
9
|
+
spec.license = 'MIT'
|
|
9
10
|
spec.version = Business::BR::VERSION
|
|
10
11
|
spec.authors = ["Daniel Vinciguerra"]
|
|
11
12
|
spec.email = ["daniel.vinciguerra@bivee.com.br"]
|
|
@@ -16,8 +17,8 @@ Gem::Specification.new do |spec|
|
|
|
16
17
|
|
|
17
18
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
18
19
|
spec.bindir = "exe"
|
|
19
|
-
#spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
20
20
|
spec.require_paths = ["lib"]
|
|
21
|
+
spec.required_ruby_version = '>= 2.0.0'
|
|
21
22
|
|
|
22
23
|
spec.add_development_dependency "bundler", "~> 1.12"
|
|
23
24
|
spec.add_development_dependency "rake", "~> 10.0"
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
module Business::BR
|
|
2
|
+
class CNPJ
|
|
3
|
+
|
|
4
|
+
def validate(cnpj)
|
|
5
|
+
return false unless cnpj
|
|
6
|
+
return false unless cnpj.length == 14 || cnpj.length == 18
|
|
7
|
+
return false unless cnpj =~ /^\d{2}\.?\d{3}\.?\d{3}\/?\d{4}-?\d{2}$/
|
|
8
|
+
|
|
9
|
+
cnpj = normalize(cnpj)
|
|
10
|
+
numbers = [6,5,4,3,2,9,8,7,6,5,4,3,2]
|
|
11
|
+
|
|
12
|
+
first_num = 0
|
|
13
|
+
second_num = 0
|
|
14
|
+
|
|
15
|
+
12.times do |i|
|
|
16
|
+
first_num += numbers[i+1] * cnpj[i].to_i
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
13.times do |i|
|
|
20
|
+
second_num += numbers[i] * cnpj[i].to_i
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
first_num %= 11
|
|
24
|
+
first_num = first_num < 2 ? 0 : (11 - first_num)
|
|
25
|
+
|
|
26
|
+
second_num %= 11
|
|
27
|
+
second_num = second_num < 2 ? 0 : (11 - second_num) == 10 ? 1 : (11 - second_num)
|
|
28
|
+
|
|
29
|
+
return false unless "#{first_num}#{second_num}" == cnpj[12..13]
|
|
30
|
+
|
|
31
|
+
true
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def normalize(cnpj)
|
|
36
|
+
"#{$1}#{$2}#{$3}#{$4}#{$5}" if cnpj =~ /^(\d{2})\.?(\d{3})\.?(\d{3})\/?(\d{4})-?(\d{2})$/
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def format(cnpj)
|
|
41
|
+
"#{$1}.#{$2}.#{$3}/#{$4}-#{$5}" if cnpj =~ /^(\d{2})\.?(\d{3})\.?(\d{3})\/?(\d{4})-?(\d{2})$/
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
end
|
|
45
|
+
end
|
data/lib/business-br/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: business-br
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.5.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Daniel Vinciguerra
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2016-09-
|
|
11
|
+
date: 2016-09-20 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -61,6 +61,7 @@ extensions: []
|
|
|
61
61
|
extra_rdoc_files: []
|
|
62
62
|
files:
|
|
63
63
|
- ".gitignore"
|
|
64
|
+
- ".travis.yml"
|
|
64
65
|
- Gemfile
|
|
65
66
|
- Gemfile.lock
|
|
66
67
|
- README.md
|
|
@@ -68,10 +69,12 @@ files:
|
|
|
68
69
|
- business-br.gemspec
|
|
69
70
|
- lib/business-br.rb
|
|
70
71
|
- lib/business-br/cep.rb
|
|
72
|
+
- lib/business-br/cnpj.rb
|
|
71
73
|
- lib/business-br/cpf.rb
|
|
72
74
|
- lib/business-br/version.rb
|
|
73
75
|
homepage: https://github.com/dvinciguerra/business-br
|
|
74
|
-
licenses:
|
|
76
|
+
licenses:
|
|
77
|
+
- MIT
|
|
75
78
|
metadata: {}
|
|
76
79
|
post_install_message:
|
|
77
80
|
rdoc_options: []
|
|
@@ -81,7 +84,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
81
84
|
requirements:
|
|
82
85
|
- - ">="
|
|
83
86
|
- !ruby/object:Gem::Version
|
|
84
|
-
version:
|
|
87
|
+
version: 2.0.0
|
|
85
88
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
86
89
|
requirements:
|
|
87
90
|
- - ">="
|