business-br 0.8.0 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 568c119ede5784bdcc4d26d3ad9d214751ad7f13
4
- data.tar.gz: 22ad8e004032f3309336cca28685656d65a54e1d
2
+ SHA256:
3
+ metadata.gz: 5015d35ac8b5d59a5ef88efb7fc651607e83198b140f5e3de7cfdbbf9550979d
4
+ data.tar.gz: 6aa6000c0f7f24ebb31f62cc9acb91ec3b3948800a27fccc9bce1bbfda4a08c8
5
5
  SHA512:
6
- metadata.gz: cb70bbc0ee1e14a894a939769e6da85a86aa8c8a223491ed0e3276e76e58364dc335dcbe21dc8b2a470a11640344dc85c6c421bb79b21bb0349e89e85bdd0bd0
7
- data.tar.gz: c409118a15e535b99964d287d49b38bfea03775d58c34844c19b89813dcd5a853ab7fec68d54a9ff2780ea2184f7b31c26bb2a105ecd482ebf7f35ae5919a1d7
6
+ metadata.gz: 6f4a12217be15d348a8e4bb3ba105051019200f10695bc6b4174f2f784562f530b0dff2ed9de10202925835ef2d1fb1a4146fd55de83991edac33fa7ad6f78d0
7
+ data.tar.gz: 32ca9d1f24712715b280b5635b1960e0fb101c81744f258aa0a8d71d5f9d7b5155aa2aaeca0b4e3169977d3c31e3abe7b79ed625f93d9d202d79d305f2597388
data/.travis.yml CHANGED
@@ -1,27 +1,29 @@
1
+ env:
2
+ global:
3
+ - COVERAGE=true
4
+
1
5
  language: ruby
2
- sudo: false
3
6
 
4
7
  rvm:
5
- - 2.3.1
6
- - 2.3.0
7
- - 2.2.3
8
- - 2.1.7
9
- - 2.0.0
10
- - jruby-9.0.5.0
11
- - jruby-19mode
12
- - ruby-head
13
-
14
- matrix:
15
- allow_failures:
16
- - rvm: jruby-19mode
17
- - rvm: jruby-head
8
+ - 2.7
9
+ - 2.6
10
+ - 2.5
11
+ - 2.4
18
12
 
19
13
  before_install:
20
- - gem install bundler
14
+ - gem update
15
+ - gem install bundler --force
21
16
 
22
- bundler_args:
23
- --without test --jobs 3 --retry 3
17
+ bundler_args: --jobs 3 --retry 3
24
18
 
25
19
  before_script:
20
+ - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
21
+ - chmod +x ./cc-test-reporter
22
+ - ./cc-test-reporter before-build
26
23
  - bundle update
27
24
 
25
+ script:
26
+ - bundle exec rspec
27
+
28
+ after_script:
29
+ - ./cc-test-reporter after-build --coverage-input-type simplecov --exit-code $TRAVIS_TEST_RESULT
data/Gemfile CHANGED
@@ -2,3 +2,4 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in business-br.gemspec
4
4
  gemspec
5
+
data/Gemfile.lock CHANGED
@@ -1,63 +1,77 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- business-br (0.7.1)
4
+ business-br (0.12.0)
5
+ faraday (~> 2.6)
5
6
  rest-client (~> 2.0)
6
7
 
7
8
  GEM
8
9
  remote: https://rubygems.org/
9
10
  specs:
10
- addressable (2.5.0)
11
- public_suffix (~> 2.0, >= 2.0.2)
12
- crack (0.4.3)
13
- safe_yaml (~> 1.0.0)
14
- diff-lcs (1.2.5)
15
- domain_name (0.5.20161129)
11
+ addressable (2.8.1)
12
+ public_suffix (>= 2.0.2, < 6.0)
13
+ crack (0.4.5)
14
+ rexml
15
+ diff-lcs (1.5.0)
16
+ docile (1.4.0)
17
+ domain_name (0.5.20190701)
16
18
  unf (>= 0.0.5, < 1.0.0)
17
- hashdiff (0.3.0)
18
- http-cookie (1.0.3)
19
+ faraday (2.6.0)
20
+ faraday-net_http (>= 2.0, < 3.1)
21
+ ruby2_keywords (>= 0.0.4)
22
+ faraday-net_http (3.0.2)
23
+ hashdiff (1.0.1)
24
+ http-accept (1.7.0)
25
+ http-cookie (1.0.5)
19
26
  domain_name (~> 0.5)
20
- mime-types (3.1)
27
+ mime-types (3.4.1)
21
28
  mime-types-data (~> 3.2015)
22
- mime-types-data (3.2016.0521)
29
+ mime-types-data (3.2022.0105)
23
30
  netrc (0.11.0)
24
- public_suffix (2.0.4)
25
- rake (10.4.2)
26
- rest-client (2.0.0)
31
+ public_suffix (5.0.0)
32
+ rake (13.0.6)
33
+ rest-client (2.1.0)
34
+ http-accept (>= 1.7.0, < 2.0)
27
35
  http-cookie (>= 1.0.2, < 2.0)
28
36
  mime-types (>= 1.16, < 4.0)
29
37
  netrc (~> 0.8)
30
- rspec (3.5.0)
31
- rspec-core (~> 3.5.0)
32
- rspec-expectations (~> 3.5.0)
33
- rspec-mocks (~> 3.5.0)
34
- rspec-core (3.5.2)
35
- rspec-support (~> 3.5.0)
36
- rspec-expectations (3.5.0)
38
+ rexml (3.2.5)
39
+ rspec (3.12.0)
40
+ rspec-core (~> 3.12.0)
41
+ rspec-expectations (~> 3.12.0)
42
+ rspec-mocks (~> 3.12.0)
43
+ rspec-core (3.12.0)
44
+ rspec-support (~> 3.12.0)
45
+ rspec-expectations (3.12.0)
37
46
  diff-lcs (>= 1.2.0, < 2.0)
38
- rspec-support (~> 3.5.0)
39
- rspec-mocks (3.5.0)
47
+ rspec-support (~> 3.12.0)
48
+ rspec-mocks (3.12.0)
40
49
  diff-lcs (>= 1.2.0, < 2.0)
41
- rspec-support (~> 3.5.0)
42
- rspec-support (3.5.0)
43
- safe_yaml (1.0.4)
50
+ rspec-support (~> 3.12.0)
51
+ rspec-support (3.12.0)
52
+ ruby2_keywords (0.0.5)
53
+ simplecov (0.18.5)
54
+ docile (~> 1.1)
55
+ simplecov-html (~> 0.11)
56
+ simplecov-html (0.12.3)
44
57
  unf (0.1.4)
45
58
  unf_ext
46
- unf_ext (0.0.7.2)
47
- webmock (2.1.0)
48
- addressable (>= 2.3.6)
59
+ unf_ext (0.0.8.2)
60
+ webmock (3.18.1)
61
+ addressable (>= 2.8.0)
49
62
  crack (>= 0.3.2)
50
- hashdiff
63
+ hashdiff (>= 0.4.0, < 2.0.0)
51
64
 
52
65
  PLATFORMS
53
66
  ruby
54
67
 
55
68
  DEPENDENCIES
56
- bundler (~> 1.12)
69
+ bundler (~> 2.1)
57
70
  business-br!
58
- rake (~> 10.0)
71
+ rake (~> 13.0)
59
72
  rspec (~> 3.0)
60
- webmock (~> 2.1, >= 2.1.0)
73
+ simplecov (~> 0.18.5)
74
+ webmock (~> 3.8)
61
75
 
62
76
  BUNDLED WITH
63
- 1.12.5
77
+ 2.1.4
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
3
5
 
4
6
  RSpec::Core::RakeTask.new(:spec)
5
7
 
6
- task :default => :spec
8
+ task default: :spec
data/business-br.gemspec CHANGED
@@ -1,34 +1,45 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
 
5
6
  require 'business-br/version'
6
7
 
7
8
  Gem::Specification.new do |spec|
8
- spec.name = "business-br"
9
+ spec.name = 'business-br'
9
10
  spec.license = 'MIT'
10
11
  spec.version = Business::BR::VERSION
11
- spec.authors = ["Daniel Vinciguerra"]
12
- spec.email = ["daniel.vinciguerra@bivee.com.br"]
12
+ spec.authors = ['Daniel Vinciguerra']
13
+ spec.email = ['daniel.vinciguerra@bivee.com.br']
14
+
15
+ spec.summary = %w[
16
+ Classes for validations and conversions to use in brazilian ruby projects.
17
+ ]
18
+
19
+ spec.description = %w[
20
+ Business::BR is a namespace to place all validations like CPF CNPJ CEP and
21
+ some other things to be used in a brazilian ruby project.
22
+ ]
23
+
24
+ spec.homepage = 'https://github.com/dvinciguerra/business-br'
13
25
 
14
- spec.summary = %q{This project provide classes for validations and conversions to use in brazilian ruby projects.}
15
- spec.description = %q{Business::BR is a namespace to place all validations like CPF, CNPJ, CEP and some other things to be used in a brazilian ruby project.}
16
- spec.homepage = "https://github.com/dvinciguerra/business-br"
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |filename|
27
+ filename.match(%r{^(test|spec|features)/})
28
+ end
17
29
 
18
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
- spec.bindir = "exe"
20
- spec.require_paths = ["lib"]
21
- spec.required_ruby_version = '>= 2.0.0'
30
+ spec.bindir = 'exe'
31
+ spec.require_paths = ['lib']
22
32
 
23
- # secirity
24
- spec.cert_chain = ['certs/dvinciguerra.pem']
25
- spec.signing_key = File.expand_path("~/.ssh/gem-private_key.pem") if $0 =~ /gem\z/
33
+ spec.required_ruby_version = '>= 2.4'
26
34
 
27
35
  # dependency
28
- spec.add_development_dependency "bundler", "~> 1.12"
29
- spec.add_development_dependency "rake", "~> 10.0"
30
- spec.add_development_dependency "rspec", "~> 3.0"
31
- spec.add_development_dependency 'webmock', '~> 2.1', '>= 2.1.0'
36
+ spec.add_development_dependency 'bundler', '~> 2.1'
37
+ spec.add_development_dependency 'rake', '~> 13.0'
38
+ spec.add_development_dependency 'rspec', '~> 3.0'
39
+ spec.add_development_dependency 'simplecov', '~> 0.18.5'
40
+ spec.add_development_dependency 'webmock', '~> 3.8'
32
41
 
42
+ spec.add_dependency 'faraday', '~> 2.6'
33
43
  spec.add_dependency 'rest-client', '~> 2.0'
44
+ spec.metadata['rubygems_mfa_required'] = 'true'
34
45
  end
data/examples/cep.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'business-br'
4
5
 
@@ -8,7 +9,6 @@ validator = Business::BR::CEP.new
8
9
  # turns from '13330-000' into '13330000'
9
10
  cep = validator.normalize(cep)
10
11
 
11
-
12
12
  # turns from '13330000' into '13330-000'
13
13
  cep = validator.format(cep)
14
14
 
@@ -18,18 +18,17 @@ cep_region = validator.region(cep) # => ['SP']
18
18
  # getting cep type
19
19
  cep_type = validator.type(cep) # => 'LOGRADOURO'
20
20
 
21
-
22
21
  # check if cep is valid
23
22
  if validator.valid? '00000asd'
24
23
  puts 'This CEP is valid'
25
- else
24
+ else
26
25
  puts 'This CEP is not valid... please try again!'
27
26
  end
28
27
 
29
28
  # getting cep information
30
- cep = Business::BR::CEP.new
29
+ cep = Business::BR::CEP.new
31
30
  if infor = cep.search_by('12345678')
32
31
  puts "CEP: #{infor}"
33
32
  else
34
- puts "NOT FOUND"
33
+ puts 'NOT FOUND'
35
34
  end
@@ -1,4 +1,7 @@
1
- require 'rest-client'
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+ require 'faraday'
2
5
 
3
6
  module Business
4
7
  module BR
@@ -8,24 +11,24 @@ module Business
8
11
  attr_accessor :zipcode
9
12
 
10
13
  protected
11
- # response entity
12
- def create_entity(json, extract:{})
13
- json = json.class == String ? decode_json(json) : json
14
14
 
15
- # getting informations
16
- extracted = Hash.new
17
- extract.each do |key, value|
18
- extracted[key] = (value.class == Symbol ? json[value] : value)
19
- end
15
+ # response entity
16
+ def create_entity(json, extract: {})
17
+ json = json.class == String ? decode_json(json) : json
20
18
 
21
- extracted
19
+ # getting informations
20
+ extracted = {}
21
+ extract.each do |key, value|
22
+ extracted[key] = (value.class == Symbol ? json[value] : value)
22
23
  end
23
24
 
24
- # decode json
25
- def decode_json(str)
26
- JSON.parse(str, symbolize_names: true)
27
- end
25
+ extracted
26
+ end
28
27
 
28
+ # decode json
29
+ def decode_json(str)
30
+ JSON.parse(str, symbolize_names: true)
31
+ end
29
32
  end
30
33
  end # Providers
31
34
  end # CEP
@@ -1,38 +1,37 @@
1
- require 'json'
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Business
4
4
  module BR
5
5
  class CEP
6
6
  class Providers
7
7
  class Postmon < Base
8
-
9
8
  def search_by(cep)
10
9
  @zipcode = cep
11
10
  begin
12
- response = RestClient.get "http://api.postmon.com.br/v1/cep/#{@zipcode}"
13
- return parse_response(response.body)
14
- rescue RestClient::ExceptionWithResponse => e
11
+ response = Faraday.get("http://api.postmon.com.br/v1/cep/#{@zipcode}")
12
+ parse_response(response.body)
13
+ rescue Faraday::ClientError => e
15
14
  puts e.response if ENV['BUSINESS-BR_DEBUG']
16
- return nil
15
+ nil
17
16
  end
18
17
  end
19
18
 
20
19
  private
21
- def parse_response(response)
22
- json = JSON.parse(response, symbolize_names: true)
23
- create_entity(
24
- json, extract: {
25
- zipcode: :cep,
26
- street: :logradouro,
27
- complement: :complemento,
28
- neighborhood: :bairro,
29
- city: :cidade,
30
- state: "#{json[:estado_info][:nome]}",
31
- uf: :estado
32
- }
33
- )
34
- end
35
20
 
21
+ def parse_response(response)
22
+ json = JSON.parse(response, symbolize_names: true)
23
+ create_entity(
24
+ json, extract: {
25
+ zipcode: :cep,
26
+ street: :logradouro,
27
+ complement: :complemento,
28
+ neighborhood: :bairro,
29
+ city: :cidade,
30
+ state: (json[:estado_info][:nome]).to_s,
31
+ uf: :estado
32
+ }
33
+ )
34
+ end
36
35
  end
37
36
  end # Providers
38
37
  end # CEP
@@ -1,32 +1,35 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Business
2
4
  module BR
3
5
  class CEP
4
6
  class Providers
5
7
  class RepublicaVirtual < Base
6
-
7
-
8
8
  def search_by(cep)
9
9
  @zipcode = cep
10
- response = RestClient.get "http://cep.republicavirtual.com.br/web_cep.php?cep=#{@zipcode}&formato=json"
11
- parse_response(response)
10
+ response = Faraday.get("http://cep.republicavirtual.com.br/web_cep.php?cep=#{@zipcode}&formato=json")
11
+ parse_response(response.body)
12
+ rescue Faraday::ClientError => e
13
+ puts e.response if ENV['BUSINESS-BR_DEBUG']
14
+ nil
12
15
  end
13
16
 
14
17
  private
15
- def parse_response(response)
16
- json = decode_json(response)
17
- create_entity(
18
- json, extract: {
19
- zipcode: @zipcode,
20
- street: "#{json[:tipo_logradouro]} #{json[:logradouro]}",
21
- complement: "",
22
- neighborhood: :bairro,
23
- city: :cidade,
24
- state: :uf,
25
- uf: :uf
26
- }
27
- )
28
- end
29
18
 
19
+ def parse_response(response)
20
+ json = decode_json(response)
21
+ create_entity(
22
+ json, extract: {
23
+ zipcode: @zipcode,
24
+ street: "#{json[:tipo_logradouro]} #{json[:logradouro]}",
25
+ complement: '',
26
+ neighborhood: :bairro,
27
+ city: :cidade,
28
+ state: :uf,
29
+ uf: :uf
30
+ }
31
+ )
32
+ end
30
33
  end
31
34
  end # Providers
32
35
  end # CEP
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative './providers/base'
2
4
  require_relative './providers/postmon'
3
5
  require_relative './providers/republicavirtual'
@@ -6,18 +8,16 @@ module Business
6
8
  module BR
7
9
  class CEP
8
10
  class Providers
9
-
10
11
  def self.get_provider(provider)
11
12
  return nil unless provider
13
+
12
14
  begin
13
- if provider_class = eval("Business::BR::CEP::Providers::#{provider}")
14
- return provider_class.new
15
- end
16
- rescue
17
- return nil
15
+ provider_class = Business::BR::CEP::Providers.const_get(provider)
16
+ provider_class.new if provider_class
17
+ rescue StandardError
18
+ nil
18
19
  end
19
20
  end
20
-
21
21
  end # Providers
22
22
  end # CEP
23
23
  end # BR
@@ -1,75 +1,72 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative './cep/providers'
2
4
 
3
5
  module Business::BR
4
6
  class CEP
5
-
6
7
  @@regions = [
7
8
  ['SP'],
8
9
  ['SP'],
9
- ['RJ', 'ES'],
10
+ %w[RJ ES],
10
11
  ['MG'],
11
- ['BA', 'SE'],
12
- ['PE', 'AL', 'PB', 'RN'],
13
- ['CE', 'PI', 'MA', 'PA', 'AM', 'AC', 'AP', 'RR'],
14
- ['DF', 'GO', 'TO', 'MT', 'MG', 'RO'],
15
- ['PR', 'SC'],
16
- ['RS'],
12
+ %w[BA SE],
13
+ %w[PE AL PB RN],
14
+ %w[CE PI MA PA AM AC AP RR],
15
+ %w[DF GO TO MT MG RO],
16
+ %w[PR SC],
17
+ ['RS']
17
18
  ]
18
-
19
19
 
20
20
  def initialize(opts = {})
21
21
  @opts = opts || {}
22
22
  end
23
23
 
24
-
25
24
  def validate(cep)
26
25
  return false unless cep =~ /^\d{5}-?\d{3}$/
27
26
  return false unless cep.length == 8 || cep.length == 9
27
+
28
28
  true
29
29
  end
30
30
 
31
-
32
31
  def valid?(cep)
33
32
  validate(cep)
34
33
  end
35
34
 
36
-
37
35
  def normalize(cep)
38
- "#{$1}#{$2}" if cep =~ /^(\d{5})-?(\d{3})$/
36
+ if cep =~ /^(\d{5})-?(\d{3})$/
37
+ "#{Regexp.last_match(1)}#{Regexp.last_match(2)}"
38
+ end
39
39
  end
40
40
 
41
-
42
41
  def format(cep)
43
- "#{$1}-#{$2}" if cep =~ /^(\d{5})-?(\d{3})$/
42
+ if cep =~ /^(\d{5})-?(\d{3})$/
43
+ "#{Regexp.last_match(1)}-#{Regexp.last_match(2)}"
44
+ end
44
45
  end
45
-
46
46
 
47
47
  def region(cep)
48
- raise Exception.new('This cep is not valid') unless valid?(cep)
48
+ raise Exception, 'This cep is not valid' unless valid?(cep)
49
+
49
50
  @@regions[cep[0].to_i]
50
51
  end
51
52
 
52
-
53
53
  def type(cep)
54
54
  cep = normalize(cep)
55
55
  suffix = cep.slice(5, 3).to_i
56
- case
57
- when suffix < 900 then 'LOGRADOURO'
58
- when suffix < 960 then 'ESPECIAL'
59
- when suffix < 970 then 'PROMOCIONAIS'
60
- when suffix < 990 || suffix == 999 then 'CORREIOS'
61
- else 'CAIXAPOSTAL';
56
+ if suffix < 900 then 'LOGRADOURO'
57
+ elsif suffix < 960 then 'ESPECIAL'
58
+ elsif suffix < 970 then 'PROMOCIONAIS'
59
+ elsif suffix < 990 || suffix == 999 then 'CORREIOS'
60
+ else 'CAIXAPOSTAL'
62
61
  end
63
62
  end
64
63
 
65
- def search_by(cep, provider:'Postmon')
64
+ def search_by(cep, provider: 'Postmon')
66
65
  if cep_provider = Business::BR::CEP::Providers.get_provider(provider)
67
66
  return cep_provider.search_by(cep)
68
67
  end
68
+
69
69
  nil
70
70
  end
71
-
72
71
  end
73
72
  end
74
-
75
-
@@ -1,23 +1,24 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Business::BR
2
4
  class CNPJ
3
-
4
5
  def validate(cnpj)
5
6
  return false unless cnpj
6
7
  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
+ return false unless cnpj =~ %r{^\d{2}\.?\d{3}\.?\d{3}/?\d{4}-?\d{2}$}
8
9
 
9
10
  cnpj = normalize(cnpj)
10
- numbers = [6,5,4,3,2,9,8,7,6,5,4,3,2]
11
+ numbers = [6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2]
11
12
 
12
13
  first_num = 0
13
14
  second_num = 0
14
15
 
15
16
  12.times do |i|
16
- first_num += numbers[i+1] * cnpj[i].to_i
17
+ first_num += numbers[i + 1] * cnpj[i].to_i
17
18
  end
18
19
 
19
20
  13.times do |i|
20
- second_num += numbers[i] * cnpj[i].to_i
21
+ second_num += numbers[i] * cnpj[i].to_i
21
22
  end
22
23
 
23
24
  first_num %= 11
@@ -26,20 +27,21 @@ module Business::BR
26
27
  second_num %= 11
27
28
  second_num = second_num < 2 ? 0 : (11 - second_num) == 10 ? 1 : (11 - second_num)
28
29
 
29
- return false unless "#{first_num}#{second_num}" == cnpj[12..13]
30
+ return false unless cnpj[12..13] == "#{first_num}#{second_num}"
30
31
 
31
32
  true
32
33
  end
33
34
 
34
-
35
35
  def normalize(cnpj)
36
- "#{$1}#{$2}#{$3}#{$4}#{$5}" if cnpj =~ /^(\d{2})\.?(\d{3})\.?(\d{3})\/?(\d{4})-?(\d{2})$/
36
+ if cnpj =~ %r{^(\d{2})\.?(\d{3})\.?(\d{3})/?(\d{4})-?(\d{2})$}
37
+ "#{Regexp.last_match(1)}#{Regexp.last_match(2)}#{Regexp.last_match(3)}#{Regexp.last_match(4)}#{Regexp.last_match(5)}"
38
+ end
37
39
  end
38
40
 
39
-
40
41
  def format(cnpj)
41
- "#{$1}.#{$2}.#{$3}/#{$4}-#{$5}" if cnpj =~ /^(\d{2})\.?(\d{3})\.?(\d{3})\/?(\d{4})-?(\d{2})$/
42
+ if cnpj =~ %r{^(\d{2})\.?(\d{3})\.?(\d{3})/?(\d{4})-?(\d{2})$}
43
+ "#{Regexp.last_match(1)}.#{Regexp.last_match(2)}.#{Regexp.last_match(3)}/#{Regexp.last_match(4)}-#{Regexp.last_match(5)}"
44
+ end
42
45
  end
43
-
44
46
  end
45
47
  end
@@ -1,16 +1,17 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Business::BR
2
4
  class CPF
3
-
4
5
  @@black_list = %w[
5
- 00000000000
6
- 11111111111
7
- 22222222222
8
- 33333333333
9
- 44444444444
10
- 55555555555
11
- 66666666666
12
- 77777777777
13
- 88888888888
6
+ 00000000000
7
+ 11111111111
8
+ 22222222222
9
+ 33333333333
10
+ 44444444444
11
+ 55555555555
12
+ 66666666666
13
+ 77777777777
14
+ 88888888888
14
15
  99999999999
15
16
  ]
16
17
 
@@ -20,12 +21,12 @@ module Business::BR
20
21
  return false unless cpf =~ /^\d{3}\.?\d{3}\.?\d{3}-?\d{2}$/
21
22
 
22
23
  cpf = normalize(cpf)
23
- return false unless not @@black_list.include? cpf
24
+ return false if @@black_list.include? cpf
24
25
 
25
26
  first_num = 0
26
27
  second_num = 0
27
28
 
28
- 9.times do |i|
29
+ 9.times do |i|
29
30
  first_num += (10 - i) * cpf[i].to_i
30
31
  end
31
32
 
@@ -39,20 +40,21 @@ module Business::BR
39
40
  second_num = (second_num * 10) % 11
40
41
  second_num = 0 if second_num == 10
41
42
 
42
- return false unless "#{first_num}#{second_num}" == cpf[9..10]
43
+ return false unless cpf[9..10] == "#{first_num}#{second_num}"
43
44
 
44
45
  true
45
46
  end
46
47
 
47
-
48
48
  def normalize(cpf)
49
- "#{$1}#{$2}#{$3}#{$4}" if cpf =~ /^(\d{3})\.?(\d{3})\.?(\d{3})-?(\d{2})$/
49
+ if cpf =~ /^(\d{3})\.?(\d{3})\.?(\d{3})-?(\d{2})$/
50
+ "#{Regexp.last_match(1)}#{Regexp.last_match(2)}#{Regexp.last_match(3)}#{Regexp.last_match(4)}"
51
+ end
50
52
  end
51
53
 
52
-
53
54
  def format(cpf)
54
- "#{$1}.#{$2}.#{$3}-#{$4}" if cpf =~ /^(\d{3})\.?(\d{3})\.?(\d{3})-?(\d{2})$/
55
+ if cpf =~ /^(\d{3})\.?(\d{3})\.?(\d{3})-?(\d{2})$/
56
+ "#{Regexp.last_match(1)}.#{Regexp.last_match(2)}.#{Regexp.last_match(3)}-#{Regexp.last_match(4)}"
57
+ end
55
58
  end
56
-
57
59
  end
58
60
  end
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Business
2
4
  module BR
3
- VERSION = "0.8.0"
5
+ VERSION = '0.12.0'
4
6
  end
5
7
  end
data/lib/business-br.rb CHANGED
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # register our paths
2
- lib_dir = File.expand_path(File.dirname(__FILE__))
4
+ lib_dir = __dir__
3
5
  $LOAD_PATH.unshift(lib_dir) unless $LOAD_PATH.include?(lib_dir)
4
6
 
5
7
  require 'business-br/version'
metadata CHANGED
@@ -1,38 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: business-br
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Vinciguerra
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
- cert_chain:
11
- - |
12
- -----BEGIN CERTIFICATE-----
13
- MIIDyDCCArCgAwIBAgIBATANBgkqhkiG9w0BAQUFADBdMRswGQYDVQQDDBJkYW5p
14
- ZWwudmluY2lndWVycmExFTATBgoJkiaJk/IsZAEZFgViaXZlZTETMBEGCgmSJomT
15
- 8ixkARkWA2NvbTESMBAGCgm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ALBs6mmvBr1D+l4mA48E9HDV5jl0vKDnB4ewBefj/GsxcQND8B+W2DDU
32
- diaADa2ZCuoGQuZU33vnJTmu7oy7ZUGOgo7qmoUAYbsn1x5la4sWQ6WHlH/UHDKJ
33
- 2N5QQXzs6+3RwTLN
34
- -----END CERTIFICATE-----
35
- date: 2017-01-19 00:00:00.000000000 Z
10
+ cert_chain: []
11
+ date: 2022-11-13 00:00:00.000000000 Z
36
12
  dependencies:
37
13
  - !ruby/object:Gem::Dependency
38
14
  name: bundler
@@ -40,28 +16,28 @@ dependencies:
40
16
  requirements:
41
17
  - - "~>"
42
18
  - !ruby/object:Gem::Version
43
- version: '1.12'
19
+ version: '2.1'
44
20
  type: :development
45
21
  prerelease: false
46
22
  version_requirements: !ruby/object:Gem::Requirement
47
23
  requirements:
48
24
  - - "~>"
49
25
  - !ruby/object:Gem::Version
50
- version: '1.12'
26
+ version: '2.1'
51
27
  - !ruby/object:Gem::Dependency
52
28
  name: rake
53
29
  requirement: !ruby/object:Gem::Requirement
54
30
  requirements:
55
31
  - - "~>"
56
32
  - !ruby/object:Gem::Version
57
- version: '10.0'
33
+ version: '13.0'
58
34
  type: :development
59
35
  prerelease: false
60
36
  version_requirements: !ruby/object:Gem::Requirement
61
37
  requirements:
62
38
  - - "~>"
63
39
  - !ruby/object:Gem::Version
64
- version: '10.0'
40
+ version: '13.0'
65
41
  - !ruby/object:Gem::Dependency
66
42
  name: rspec
67
43
  requirement: !ruby/object:Gem::Requirement
@@ -77,25 +53,47 @@ dependencies:
77
53
  - !ruby/object:Gem::Version
78
54
  version: '3.0'
79
55
  - !ruby/object:Gem::Dependency
80
- name: webmock
56
+ name: simplecov
81
57
  requirement: !ruby/object:Gem::Requirement
82
58
  requirements:
83
59
  - - "~>"
84
60
  - !ruby/object:Gem::Version
85
- version: '2.1'
86
- - - ">="
61
+ version: 0.18.5
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.18.5
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
87
74
  - !ruby/object:Gem::Version
88
- version: 2.1.0
75
+ version: '3.8'
89
76
  type: :development
90
77
  prerelease: false
91
78
  version_requirements: !ruby/object:Gem::Requirement
92
79
  requirements:
93
80
  - - "~>"
94
81
  - !ruby/object:Gem::Version
95
- version: '2.1'
96
- - - ">="
82
+ version: '3.8'
83
+ - !ruby/object:Gem::Dependency
84
+ name: faraday
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '2.6'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
97
95
  - !ruby/object:Gem::Version
98
- version: 2.1.0
96
+ version: '2.6'
99
97
  - !ruby/object:Gem::Dependency
100
98
  name: rest-client
101
99
  requirement: !ruby/object:Gem::Requirement
@@ -110,8 +108,9 @@ dependencies:
110
108
  - - "~>"
111
109
  - !ruby/object:Gem::Version
112
110
  version: '2.0'
113
- description: Business::BR is a namespace to place all validations like CPF, CNPJ,
114
- CEP and some other things to be used in a brazilian ruby project.
111
+ description: '["Business::BR", "is", "a", "namespace", "to", "place", "all", "validations",
112
+ "like", "CPF", "CNPJ", "CEP", "and", "some", "other", "things", "to", "be", "used",
113
+ "in", "a", "brazilian", "ruby", "project."]'
115
114
  email:
116
115
  - daniel.vinciguerra@bivee.com.br
117
116
  executables: []
@@ -125,7 +124,6 @@ files:
125
124
  - README.md
126
125
  - Rakefile
127
126
  - business-br.gemspec
128
- - certs/dvinciguerra.pem
129
127
  - examples/cep.rb
130
128
  - lib/business-br.rb
131
129
  - lib/business-br/cep.rb
@@ -139,8 +137,9 @@ files:
139
137
  homepage: https://github.com/dvinciguerra/business-br
140
138
  licenses:
141
139
  - MIT
142
- metadata: {}
143
- post_install_message:
140
+ metadata:
141
+ rubygems_mfa_required: 'true'
142
+ post_install_message:
144
143
  rdoc_options: []
145
144
  require_paths:
146
145
  - lib
@@ -148,17 +147,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
148
147
  requirements:
149
148
  - - ">="
150
149
  - !ruby/object:Gem::Version
151
- version: 2.0.0
150
+ version: '2.4'
152
151
  required_rubygems_version: !ruby/object:Gem::Requirement
153
152
  requirements:
154
153
  - - ">="
155
154
  - !ruby/object:Gem::Version
156
155
  version: '0'
157
156
  requirements: []
158
- rubyforge_project:
159
- rubygems_version: 2.5.1
160
- signing_key:
157
+ rubygems_version: 3.3.7
158
+ signing_key:
161
159
  specification_version: 4
162
- summary: This project provide classes for validations and conversions to use in brazilian
163
- ruby projects.
160
+ summary: '["Classes", "for", "validations", "and", "conversions", "to", "use", "in",
161
+ "brazilian", "ruby", "projects."]'
164
162
  test_files: []
checksums.yaml.gz.sig DELETED
@@ -1,2 +0,0 @@
1
- �ͩ �;��%ڠ���Dž>\�t�u>c- �c�9 �R�+��΃�=�5���W��:�bH\>�y�9�!�d��UR����$�t;�g�G7�G?h#�g>�w�������udN�rp#m]ޙ��WS#)��gʋ�Mp�l�%Ӗ��>���W�S$�c6��6=^G������FQ�Y���r;?�I�|��[�D����2�Im��~�N?��H�PT��L�;�Qgr��!�9ήD�N�(̭�b�
2
- ��� �9`c�NF�]���9
@@ -1,23 +0,0 @@
1
- -----BEGIN CERTIFICATE-----
2
- MIIDyDCCArCgAwIBAgIBATANBgkqhkiG9w0BAQUFADBdMRswGQYDVQQDDBJkYW5p
3
- ZWwudmluY2lndWVycmExFTATBgoJkiaJk/IsZAEZFgViaXZlZTETMBEGCgmSJomT
4
- 8ixkARkWA2NvbTESMBAGCgmSJomT8ixkARkWAmJyMB4XDTE2MTEyMzE4MzM1NloX
5
- DTE3MTEyMzE4MzM1NlowXTEbMBkGA1UEAwwSZGFuaWVsLnZpbmNpZ3VlcnJhMRUw
6
- EwY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/UHDKJ
22
- 2N5QQXzs6+3RwTLN
23
- -----END CERTIFICATE-----
data.tar.gz.sig DELETED
Binary file
metadata.gz.sig DELETED
@@ -1,2 +0,0 @@
1
- ��o̬g_��:�7GD$��䍨m|�el$�pp���j��)ɰL�:�)��:b�
2
- �?-E�V��q]�쯀F�&�?�������y��� �{B�,�è�ۘ�1⻄�M����pi^�+�{qт�'�=��~�]�d��ٵ���Zs���;���� /�i&�l�F<Mb%<�g�HF���<_J�3�b=�:�i��<S�