br_documents 0.0.15 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/config.yml +54 -0
  3. data/.gitignore +1 -1
  4. data/.rubocop.yml +65 -0
  5. data/Gemfile +1 -1
  6. data/Gemfile.lock +100 -0
  7. data/README.md +58 -1
  8. data/Rakefile +3 -3
  9. data/br_documents.gemspec +23 -19
  10. data/lib/br_documents.rb +3 -3
  11. data/lib/br_documents/cnpj_cpf/cnpj.rb +2 -2
  12. data/lib/br_documents/cnpj_cpf/cpf.rb +2 -2
  13. data/lib/br_documents/cnpj_cpf/document.rb +9 -9
  14. data/lib/br_documents/cnpj_validator.rb +4 -4
  15. data/lib/br_documents/commons/mod11.rb +1 -2
  16. data/lib/br_documents/commons/mod14.rb +20 -0
  17. data/lib/br_documents/cpf_validator.rb +4 -4
  18. data/lib/br_documents/gtin/gtin.rb +28 -0
  19. data/lib/br_documents/gtin_validator.rb +8 -0
  20. data/lib/br_documents/ie/ac.rb +3 -2
  21. data/lib/br_documents/ie/al.rb +2 -1
  22. data/lib/br_documents/ie/am.rb +3 -2
  23. data/lib/br_documents/ie/ap.rb +20 -16
  24. data/lib/br_documents/ie/ba.rb +28 -25
  25. data/lib/br_documents/ie/base.rb +1 -1
  26. data/lib/br_documents/ie/ce.rb +3 -2
  27. data/lib/br_documents/ie/df.rb +3 -2
  28. data/lib/br_documents/ie/es.rb +2 -1
  29. data/lib/br_documents/ie/factory.rb +3 -3
  30. data/lib/br_documents/ie/go.rb +3 -2
  31. data/lib/br_documents/ie/ma.rb +2 -1
  32. data/lib/br_documents/ie/mg.rb +14 -17
  33. data/lib/br_documents/ie/ms.rb +2 -1
  34. data/lib/br_documents/ie/mt.rb +6 -5
  35. data/lib/br_documents/ie/pa.rb +3 -2
  36. data/lib/br_documents/ie/pattern1.rb +10 -7
  37. data/lib/br_documents/ie/pattern2.rb +9 -8
  38. data/lib/br_documents/ie/pb.rb +3 -2
  39. data/lib/br_documents/ie/pe.rb +10 -10
  40. data/lib/br_documents/ie/pi.rb +2 -1
  41. data/lib/br_documents/ie/pr.rb +3 -2
  42. data/lib/br_documents/ie/rj.rb +3 -2
  43. data/lib/br_documents/ie/rn.rb +19 -16
  44. data/lib/br_documents/ie/ro.rb +17 -14
  45. data/lib/br_documents/ie/rr.rb +4 -3
  46. data/lib/br_documents/ie/rs.rb +3 -2
  47. data/lib/br_documents/ie/sc.rb +3 -2
  48. data/lib/br_documents/ie/se.rb +3 -2
  49. data/lib/br_documents/ie/sp.rb +17 -14
  50. data/lib/br_documents/ie/to.rb +6 -5
  51. data/lib/br_documents/ie_validator.rb +16 -15
  52. data/lib/br_documents/suframa/suframa.rb +60 -0
  53. data/lib/br_documents/suframa_validator.rb +8 -0
  54. data/lib/br_documents/version.rb +1 -1
  55. data/spec/cnpj_cpf/cnpj_spec.rb +21 -21
  56. data/spec/cnpj_cpf/cpf_spec.rb +21 -21
  57. data/spec/cnpj_validator_spec.rb +12 -12
  58. data/spec/cpf_validator_spec.rb +12 -12
  59. data/spec/gtin/gtin_spec.rb +49 -0
  60. data/spec/gtin_validator_spec.rb +47 -0
  61. data/spec/ie/ac_spec.rb +16 -16
  62. data/spec/ie/al_spec.rb +14 -14
  63. data/spec/ie/am_spec.rb +16 -16
  64. data/spec/ie/ap_spec.rb +14 -14
  65. data/spec/ie/ba_spec.rb +28 -28
  66. data/spec/ie/ce_spec.rb +9 -9
  67. data/spec/ie/df_spec.rb +16 -16
  68. data/spec/ie/es_spec.rb +9 -9
  69. data/spec/ie/factory_spec.rb +88 -89
  70. data/spec/ie/go_spec.rb +16 -16
  71. data/spec/ie/ma_spec.rb +9 -9
  72. data/spec/ie/mg_spec.rb +16 -16
  73. data/spec/ie/ms_spec.rb +9 -9
  74. data/spec/ie/mt_spec.rb +17 -17
  75. data/spec/ie/pa_spec.rb +16 -16
  76. data/spec/ie/pb_spec.rb +9 -9
  77. data/spec/ie/pe_spec.rb +27 -27
  78. data/spec/ie/pi_spec.rb +9 -9
  79. data/spec/ie/pr_spec.rb +14 -14
  80. data/spec/ie/rj_spec.rb +16 -16
  81. data/spec/ie/rn_spec.rb +27 -27
  82. data/spec/ie/ro_spec.rb +27 -27
  83. data/spec/ie/rr_spec.rb +16 -16
  84. data/spec/ie/rs_spec.rb +16 -16
  85. data/spec/ie/sc_spec.rb +16 -16
  86. data/spec/ie/se_spec.rb +9 -9
  87. data/spec/ie/shared_examples_for_pattern1.rb +11 -11
  88. data/spec/ie/shared_examples_for_to_remove_all_masks.rb +7 -8
  89. data/spec/ie/sp_spec.rb +19 -19
  90. data/spec/ie/to_spec.rb +35 -35
  91. data/spec/ie_validator_spec.rb +43 -31
  92. data/spec/spec_helper.rb +9 -6
  93. data/spec/suframa/suframa_spec.rb +109 -0
  94. data/spec/suframa_validator_spec.rb +36 -0
  95. data/spec/support/utilities.rb +2 -2
  96. metadata +94 -25
  97. data/.travis.yml +0 -6
  98. data/circle.yml +0 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 85b3dba0a5cb19581015f983a1ec5f186521756d
4
- data.tar.gz: f4166ebcf7711bc8849438bd317649ce0c02a5a4
2
+ SHA256:
3
+ metadata.gz: 26654dc4bd73502f9cf3fadf4a33104f218a47fb81e02c71c8a23f9d78c75d91
4
+ data.tar.gz: 5ec58159f531151f3b759ac907d3d16dfd269fb3a26091f559a6e23798bcce07
5
5
  SHA512:
6
- metadata.gz: 74be958176462d91c7eeb8779b0976191dd34fdf361b086717806d1462ffcb9d89b08c63fc2efb20513986e70ac8056e9876531d16c391793dabcc340b2109d2
7
- data.tar.gz: 69fc04d5fa9cc32d5b52544b094281fa923cec602c11a92f7ea58752e9d4f0400e2b08a2141104e8b356e49e3d2d0b969b05b117337a917d4e1e46ce787aff0f
6
+ metadata.gz: 724248b106f9db144d555521a59728e100e881e77261d25d2399d630e10461694adc241b027f6b53577db2d3f68ab11806d6fecaf76261bf98401d0daef780a8
7
+ data.tar.gz: 05b814e328dec4ef44f0ebe2f5af18a86ea35d920cb5537ca235e8ba30c2786a550577e4f86fc232d6760d9b589557a76c29f1c09f2848ad305ae1e8d184707b
@@ -0,0 +1,54 @@
1
+ name: Containers
2
+
3
+ on: [push]
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-latest
8
+
9
+ steps:
10
+ - uses: actions/checkout@v2
11
+
12
+ - uses: ruby/setup-ruby@v1
13
+ with:
14
+ ruby-version: 2.7.3
15
+ bundler-cache: true
16
+
17
+ rspec:
18
+ runs-on: ubuntu-latest
19
+
20
+ needs: build
21
+
22
+ steps:
23
+ - uses: actions/checkout@v2
24
+
25
+ - uses: ruby/setup-ruby@v1
26
+ with:
27
+ ruby-version: 2.7.3
28
+ bundler-cache: true
29
+
30
+ - run: |
31
+ curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
32
+ chmod +x ./cc-test-reporter
33
+ - run: |
34
+ ./cc-test-reporter before-build
35
+ bundle exec rspec
36
+ ./cc-test-reporter after-build -r $CC_TEST_REPORTER_ID --exit-code $?
37
+ env:
38
+ CC_TEST_REPORTER_ID: ${{secrets.CC_TEST_REPORTER_ID}}
39
+
40
+ lint:
41
+ runs-on: ubuntu-latest
42
+
43
+ needs: build
44
+
45
+ steps:
46
+
47
+ - uses: actions/checkout@v2
48
+
49
+ - uses: ruby/setup-ruby@v1
50
+ with:
51
+ ruby-version: 2.7.3
52
+ bundler-cache: true
53
+
54
+ - run: bundle exec rubocop --display-cop-names --parallel
data/.gitignore CHANGED
@@ -4,7 +4,7 @@
4
4
  .config
5
5
  .yardoc
6
6
  .idea/
7
- Gemfile.lock
7
+ .byebug_history
8
8
  InstalledFiles
9
9
  _yardoc
10
10
  coverage
data/.rubocop.yml ADDED
@@ -0,0 +1,65 @@
1
+ # Offense count: 1
2
+ # Configuration parameters: Include.
3
+ # Include: **/*.gemspec
4
+ Gemspec/RequiredRubyVersion:
5
+ Exclude:
6
+ - 'br_documents.gemspec'
7
+
8
+ # Offense count: 1
9
+ # Configuration parameters: Include.
10
+ # Include: **/*.gemspec
11
+ Gemspec/RubyVersionGlobalsUsage:
12
+ Exclude:
13
+ - 'br_documents.gemspec'
14
+
15
+ # Offense count: 1
16
+ # Configuration parameters: IgnoredMethods, CountRepeatedAttributes.
17
+ Metrics/AbcSize:
18
+ Max: 20
19
+
20
+ Metrics/BlockLength:
21
+ Exclude:
22
+ - 'spec/**/*.rb'
23
+
24
+ Style/Documentation:
25
+ Enabled: false
26
+
27
+ Style/FrozenStringLiteralComment:
28
+ EnforcedStyle: never # default: always
29
+
30
+ # Offense count: 39
31
+ # Cop supports --auto-correct.
32
+ Style/RedundantRegexpEscape:
33
+ Enabled: false
34
+
35
+ # Offense count: 18
36
+ # Cop supports --auto-correct.
37
+ # Configuration parameters: EnforcedStyle, AllowInnerSlashes.
38
+ # SupportedStyles: slashes, percent_r, mixed
39
+ Style/RegexpLiteral:
40
+ Exclude:
41
+ - 'lib/br_documents/cnpj_cpf/cnpj.rb'
42
+ - 'lib/br_documents/cnpj_cpf/document.rb'
43
+ - 'lib/br_documents/ie/ac.rb'
44
+ - 'lib/br_documents/ie/ba.rb'
45
+ - 'lib/br_documents/ie/mg.rb'
46
+ - 'lib/br_documents/ie/mt.rb'
47
+ - 'lib/br_documents/ie/pattern1.rb'
48
+ - 'lib/br_documents/ie/pattern2.rb'
49
+ - 'lib/br_documents/ie/pe.rb'
50
+ - 'lib/br_documents/ie/rn.rb'
51
+ - 'lib/br_documents/ie/ro.rb'
52
+ - 'lib/br_documents/ie/rs.rb'
53
+ - 'lib/br_documents/ie/sp.rb'
54
+ - 'spec/ie/shared_examples_for_to_remove_all_masks.rb'
55
+
56
+ # Offense count: 1
57
+ # Cop supports --auto-correct.
58
+ # Configuration parameters: EnforcedStyle.
59
+ # SupportedStyles: use_perl_names, use_english_names
60
+ Style/SpecialGlobalVars:
61
+ Exclude:
62
+ - 'br_documents.gemspec'
63
+
64
+ Style/WordArray:
65
+ EnforcedStyle: brackets
data/Gemfile CHANGED
@@ -1,3 +1,3 @@
1
- source "https://rubygems.org"
1
+ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,100 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ br_documents (0.2.0)
5
+ activemodel (>= 4.0.0)
6
+ i18n (>= 0.6.5)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activemodel (6.1.3.2)
12
+ activesupport (= 6.1.3.2)
13
+ activesupport (6.1.3.2)
14
+ concurrent-ruby (~> 1.0, >= 1.0.2)
15
+ i18n (>= 1.6, < 2)
16
+ minitest (>= 5.1)
17
+ tzinfo (~> 2.0)
18
+ zeitwerk (~> 2.3)
19
+ ast (2.4.2)
20
+ byebug (11.1.3)
21
+ codeclimate-test-reporter (1.0.7)
22
+ simplecov
23
+ concurrent-ruby (1.1.9)
24
+ diff-lcs (1.4.4)
25
+ docile (1.4.0)
26
+ i18n (1.8.10)
27
+ concurrent-ruby (~> 1.0)
28
+ minitest (5.14.4)
29
+ parallel (1.20.1)
30
+ parser (3.0.1.1)
31
+ ast (~> 2.4.1)
32
+ rack (2.2.3)
33
+ rainbow (3.0.0)
34
+ rake (13.0.3)
35
+ regexp_parser (2.1.1)
36
+ rexml (3.2.5)
37
+ rspec (3.10.0)
38
+ rspec-core (~> 3.10.0)
39
+ rspec-expectations (~> 3.10.0)
40
+ rspec-mocks (~> 3.10.0)
41
+ rspec-core (3.10.1)
42
+ rspec-support (~> 3.10.0)
43
+ rspec-expectations (3.10.1)
44
+ diff-lcs (>= 1.2.0, < 2.0)
45
+ rspec-support (~> 3.10.0)
46
+ rspec-mocks (3.10.2)
47
+ diff-lcs (>= 1.2.0, < 2.0)
48
+ rspec-support (~> 3.10.0)
49
+ rspec-support (3.10.2)
50
+ rubocop (1.15.0)
51
+ parallel (~> 1.10)
52
+ parser (>= 3.0.0.0)
53
+ rainbow (>= 2.2.2, < 4.0)
54
+ regexp_parser (>= 1.8, < 3.0)
55
+ rexml
56
+ rubocop-ast (>= 1.5.0, < 2.0)
57
+ ruby-progressbar (~> 1.7)
58
+ unicode-display_width (>= 1.4.0, < 3.0)
59
+ rubocop-ast (1.7.0)
60
+ parser (>= 3.0.1.1)
61
+ rubocop-performance (1.11.3)
62
+ rubocop (>= 1.7.0, < 2.0)
63
+ rubocop-ast (>= 0.4.0)
64
+ rubocop-rails (2.10.1)
65
+ activesupport (>= 4.2.0)
66
+ rack (>= 1.1)
67
+ rubocop (>= 1.7.0, < 2.0)
68
+ rubocop-rspec (2.3.0)
69
+ rubocop (~> 1.0)
70
+ rubocop-ast (>= 1.1.0)
71
+ ruby-progressbar (1.11.0)
72
+ simplecov (0.21.2)
73
+ docile (~> 1.1)
74
+ simplecov-html (~> 0.11)
75
+ simplecov_json_formatter (~> 0.1)
76
+ simplecov-html (0.12.3)
77
+ simplecov_json_formatter (0.1.3)
78
+ tzinfo (2.0.4)
79
+ concurrent-ruby (~> 1.0)
80
+ unicode-display_width (2.0.0)
81
+ zeitwerk (2.4.2)
82
+
83
+ PLATFORMS
84
+ ruby
85
+
86
+ DEPENDENCIES
87
+ br_documents!
88
+ bundler (>= 1.3)
89
+ byebug (= 11.1.3)
90
+ codeclimate-test-reporter (>= 1.0.7)
91
+ rake (>= 13.0.3)
92
+ rspec (>= 3.10.0)
93
+ rubocop (~> 1.15.0)
94
+ rubocop-performance (~> 1.11.3)
95
+ rubocop-rails (~> 2.10.1)
96
+ rubocop-rspec (~> 2.3.0)
97
+ simplecov (>= 0.21.2)
98
+
99
+ BUNDLED WITH
100
+ 2.1.4
data/README.md CHANGED
@@ -115,6 +115,29 @@ pj.ie = "111.111.111"
115
115
  pj.valid? # => false
116
116
  ```
117
117
 
118
+ #### SUFRAMA
119
+
120
+ ```ruby
121
+ class Person < ActiveRecord::Base
122
+
123
+ attr_accessor :suframa
124
+
125
+ validates :suframa,
126
+ suframa: true
127
+ end
128
+
129
+
130
+ pj = Person.new
131
+ pj.suframa = "100698107"
132
+ pj.valid? # => true
133
+
134
+ pj.suframa = "10.0698.107" # with mask
135
+ pj.valid? # => true
136
+
137
+ pj.suframa = "11.1111.111"
138
+ pj.valid? # => false
139
+ ```
140
+
118
141
  ### Ruby
119
142
 
120
143
  #### CNPJ
@@ -147,9 +170,43 @@ ie.formatted # => "254.062.407"
147
170
  ie.valid? # => true
148
171
  ```
149
172
 
173
+ #### SUFRAMA
174
+
175
+ ```ruby
176
+ require "br_documents"
177
+
178
+ suframa = BrDocuments::Suframa.new("100698107")
179
+ suframa.formatted # => "10.0698.107"
180
+ suframa.valid? # => true
181
+ ```
182
+
183
+ ## Environment variables
184
+
185
+ The following variables are necessary to be set:
186
+
187
+ Environment var | Development? | Test? | CI | Production? | Data
188
+ -------------------------------|--------------|-------|-----|-------------|-----
189
+ TZ | no | no | yes | no | America/Sao_Paulo
190
+ BUNDLE_PATH | no | no | yes | no | ./vendor/bundle
191
+ CC_TEST_REPORTER_ID | no | no | yes | no | get at codeclimate
192
+ RAILS_ENV | no | no | yes | no | test
193
+
194
+ ## Deploy to Rubygems
195
+
196
+ $ bundle exec rake release # Create tag vX.X.X, build and push br_documents-X.X.X.gem to Rubygems
197
+
198
+ You can build or install using one of the above tasks
199
+
200
+ $ bundle exec rake build # Build br_documents-X.X.X.gem into the pkg directory
201
+ $ bundle exec rake install # Build and install br_documents-X.X.X.gem into system gems
202
+
203
+ #### Login
204
+ $ gem signin
205
+ $ gem signout
206
+
150
207
  ## How to add contributors
151
208
 
152
- gem owner --add leandrolourenci@gmail.com br_documents
209
+ gem owner --add leandrolourenci@gmail.com br_documents
153
210
 
154
211
  ## Contributing
155
212
 
data/Rakefile CHANGED
@@ -1,10 +1,10 @@
1
- require "rspec/core/rake_task"
2
- require "bundler/gem_tasks"
1
+ require 'rspec/core/rake_task'
2
+ require 'bundler/gem_tasks'
3
3
 
4
4
  task default: :spec
5
5
  RSpec::Core::RakeTask.new
6
6
 
7
7
  desc "Open an irb session preloaded class's"
8
8
  task :console do
9
- sh "irb -rubygems -I lib -r br_documents.rb"
9
+ sh 'irb -rubygems -I lib -r br_documents.rb'
10
10
  end
data/br_documents.gemspec CHANGED
@@ -1,30 +1,34 @@
1
- # coding: utf-8
2
- lib = File.expand_path("../lib", __FILE__)
1
+ lib = File.expand_path('lib', __dir__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require "br_documents/version"
3
+ require 'br_documents/version'
5
4
 
6
5
  Gem::Specification.new do |spec|
7
- spec.name = "br_documents"
6
+ spec.name = 'br_documents'
8
7
  spec.version = BrDocuments::VERSION
9
- spec.authors = ["ASSEINFO - Sistemas de Informação"]
10
- spec.email = ["asseinfo@asseinfo.com.br"]
11
- spec.description = "Validates brazilian documents like CPF, CNPJ and IE."
12
- spec.summary = "Validates brazilian documents like CPF, CNPJ and IE. It can be used with active record or just in ruby."
13
- spec.homepage = "http://github.com/asseinfo/br_documents"
14
- spec.license = "MIT"
8
+ spec.authors = ['ASSEINFO - Sistemas de Informação']
9
+ spec.email = ['asseinfo@asseinfo.com.br']
10
+ spec.description = 'Validates brazilian documents like CPF, CNPJ and IE.'
11
+ spec.summary = 'Validates brazilian documents like CPF, CNPJ and IE. It can be used with active record '\
12
+ 'or just in ruby.'
13
+ spec.homepage = 'http://github.com/asseinfo/br_documents'
14
+ spec.license = 'MIT'
15
15
 
16
16
  spec.files = `git ls-files`.split($/)
17
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
19
+ spec.require_paths = ['lib']
20
20
 
21
- spec.add_dependency "activemodel", ">= 4.0.0"
22
- spec.add_dependency "i18n", ">= 0.6.5"
21
+ spec.add_dependency 'activemodel', '>= 4.0.0'
22
+ spec.add_dependency 'i18n', '>= 0.6.5'
23
23
 
24
- spec.add_development_dependency "bundler", ">= 1.3"
25
- spec.add_development_dependency "rake", ">= 10.1.0"
26
- spec.add_development_dependency "rspec", ">= 3.0.0"
27
- spec.add_development_dependency "codeclimate-test-reporter"
28
- spec.add_development_dependency "simplecov", ">= 0.9.0"
29
- spec.add_development_dependency "byebug", "4.0.1" if RUBY_VERSION >= "2.0"
24
+ spec.add_development_dependency 'bundler', '>= 1.3'
25
+ spec.add_development_dependency 'byebug', '11.1.3' if RUBY_VERSION >= '2.0'
26
+ spec.add_development_dependency 'codeclimate-test-reporter', '>= 1.0.7'
27
+ spec.add_development_dependency 'rake', '>= 13.0.3'
28
+ spec.add_development_dependency 'rspec', '>= 3.10.0'
29
+ spec.add_development_dependency 'rubocop', '~> 1.15.0'
30
+ spec.add_development_dependency 'rubocop-performance', '~> 1.11.3'
31
+ spec.add_development_dependency 'rubocop-rails', '~> 2.10.1'
32
+ spec.add_development_dependency 'rubocop-rspec', '~> 2.3.0'
33
+ spec.add_development_dependency 'simplecov', '>= 0.21.2'
30
34
  end
data/lib/br_documents.rb CHANGED
@@ -1,5 +1,5 @@
1
- require "active_model"
1
+ require 'active_model'
2
2
 
3
- Dir[File.dirname(__FILE__) + "/**/*.rb"].each { |f| require f }
3
+ Dir["#{File.dirname(__FILE__)}/**/*.rb"].sort.each { |f| require f }
4
4
 
5
- I18n.load_path << File.expand_path("../../config/locales/pt-BR.yml", __FILE__)
5
+ I18n.load_path << File.expand_path('../config/locales/pt-BR.yml', __dir__)
@@ -1,4 +1,4 @@
1
- require_relative "document"
1
+ require_relative 'document'
2
2
 
3
3
  module BrDocuments
4
4
  module CnpjCpf
@@ -16,7 +16,7 @@ module BrDocuments
16
16
  end
17
17
 
18
18
  def format_number
19
- @number.sub(/(\d{2})(\d{3})(\d{3})(\d{4})(\d{2})/, "\\1.\\2.\\3/\\4-\\5")
19
+ @number.sub(/(\d{2})(\d{3})(\d{3})(\d{4})(\d{2})/, '\\1.\\2.\\3/\\4-\\5')
20
20
  end
21
21
  end
22
22
  end
@@ -1,4 +1,4 @@
1
- require_relative "document"
1
+ require_relative 'document'
2
2
 
3
3
  module BrDocuments
4
4
  module CnpjCpf
@@ -16,7 +16,7 @@ module BrDocuments
16
16
  end
17
17
 
18
18
  def format_number
19
- @number.sub(/(\d{3})(\d{3})(\d{3})(\d{2})/, "\\1.\\2.\\3-\\4")
19
+ @number.sub(/(\d{3})(\d{3})(\d{3})(\d{2})/, '\\1.\\2.\\3-\\4')
20
20
  end
21
21
  end
22
22
  end
@@ -1,4 +1,4 @@
1
- require_relative "../commons/mod11"
1
+ require_relative '../commons/mod11'
2
2
 
3
3
  module BrDocuments
4
4
  module CnpjCpf
@@ -10,11 +10,11 @@ module BrDocuments
10
10
  end
11
11
 
12
12
  def valid?
13
- valid_format? && !sequence_of_equal_numbers? && valid_digital_check?
13
+ valid_format? && !sequence_of_equal_numbers? && valid_check_digit?
14
14
  end
15
15
 
16
16
  def formatted
17
- valid? ? format_number : ""
17
+ valid? ? format_number : ''
18
18
  end
19
19
 
20
20
  private
@@ -24,19 +24,19 @@ module BrDocuments
24
24
  end
25
25
 
26
26
  def sequence_of_equal_numbers?
27
- number_without_mask.split("").uniq.length == 1
27
+ number_without_mask.split('').uniq.length == 1
28
28
  end
29
29
 
30
- def valid_digital_check?
30
+ def valid_check_digit?
31
31
  weight1, weight2 = weights_for_digital_check
32
32
 
33
- digital_check1 = generate_digital_check(number_without_mask, weight1)
34
- digital_check2 = generate_digital_check(number_without_mask, weight2)
35
- @number[-2, 2].eql? "#{digital_check1}#{digital_check2}"
33
+ digital_check1 = generate_check_digit(number_without_mask, weight1)
34
+ digital_check2 = generate_check_digit(number_without_mask, weight2)
35
+ @number[-2, 2] == "#{digital_check1}#{digital_check2}"
36
36
  end
37
37
 
38
38
  def number_without_mask
39
- @number.gsub(/[\.\/-]/, "")
39
+ @number.gsub(/[\.\/-]/, '')
40
40
  end
41
41
  end
42
42
  end