br_documents 0.1.3 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (131) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/config.yml +40 -0
  3. data/.rubocop.yml +73 -0
  4. data/.tool-versions +1 -0
  5. data/Gemfile +1 -1
  6. data/Gemfile.lock +79 -42
  7. data/README.md +33 -0
  8. data/Rakefile +4 -4
  9. data/br_documents.gemspec +26 -19
  10. data/lib/br_documents/cnpj_cpf/cnpj.rb +2 -2
  11. data/lib/br_documents/cnpj_cpf/cpf.rb +2 -2
  12. data/lib/br_documents/cnpj_cpf/document.rb +9 -9
  13. data/lib/br_documents/cnpj_validator.rb +4 -4
  14. data/lib/br_documents/commons/mod11.rb +1 -2
  15. data/lib/br_documents/commons/mod14.rb +1 -2
  16. data/lib/br_documents/cpf_validator.rb +4 -4
  17. data/lib/br_documents/{gtin/gtin.rb → gtin.rb} +3 -3
  18. data/lib/br_documents/gtin_validator.rb +6 -6
  19. data/lib/br_documents/ie/ac.rb +3 -2
  20. data/lib/br_documents/ie/al.rb +2 -1
  21. data/lib/br_documents/ie/am.rb +3 -2
  22. data/lib/br_documents/ie/ap.rb +20 -16
  23. data/lib/br_documents/ie/ba.rb +28 -25
  24. data/lib/br_documents/ie/base.rb +1 -1
  25. data/lib/br_documents/ie/ce.rb +3 -2
  26. data/lib/br_documents/ie/df.rb +3 -2
  27. data/lib/br_documents/ie/es.rb +2 -1
  28. data/lib/br_documents/ie/factory.rb +3 -3
  29. data/lib/br_documents/ie/go.rb +3 -2
  30. data/lib/br_documents/ie/ma.rb +2 -1
  31. data/lib/br_documents/ie/mg.rb +14 -17
  32. data/lib/br_documents/ie/ms.rb +2 -1
  33. data/lib/br_documents/ie/mt.rb +6 -5
  34. data/lib/br_documents/ie/pa.rb +3 -2
  35. data/lib/br_documents/ie/pattern1.rb +10 -7
  36. data/lib/br_documents/ie/pattern2.rb +9 -8
  37. data/lib/br_documents/ie/pb.rb +3 -2
  38. data/lib/br_documents/ie/pe.rb +10 -10
  39. data/lib/br_documents/ie/pi.rb +2 -1
  40. data/lib/br_documents/ie/pr.rb +3 -2
  41. data/lib/br_documents/ie/rj.rb +3 -2
  42. data/lib/br_documents/ie/rn.rb +19 -16
  43. data/lib/br_documents/ie/ro.rb +16 -13
  44. data/lib/br_documents/ie/rr.rb +4 -3
  45. data/lib/br_documents/ie/rs.rb +3 -2
  46. data/lib/br_documents/ie/sc.rb +3 -2
  47. data/lib/br_documents/ie/se.rb +3 -2
  48. data/lib/br_documents/ie/sp.rb +17 -14
  49. data/lib/br_documents/ie/to.rb +6 -5
  50. data/lib/br_documents/ie_validator.rb +7 -7
  51. data/lib/br_documents/suframa.rb +46 -0
  52. data/lib/br_documents/suframa_validator.rb +8 -0
  53. data/lib/br_documents/version.rb +1 -1
  54. data/lib/br_documents.rb +3 -3
  55. data/spec/br_documents/cnpj_cpf/cnpj_spec.rb +59 -0
  56. data/spec/br_documents/cnpj_cpf/cpf_spec.rb +59 -0
  57. data/spec/br_documents/cnpj_validator_spec.rb +36 -0
  58. data/spec/br_documents/cpf_validator_spec.rb +36 -0
  59. data/spec/{gtin → br_documents}/gtin_spec.rb +4 -4
  60. data/spec/{gtin_validator_spec.rb → br_documents/gtin_validator_spec.rb} +14 -14
  61. data/spec/br_documents/ie/ac_spec.rb +43 -0
  62. data/spec/br_documents/ie/al_spec.rb +36 -0
  63. data/spec/br_documents/ie/am_spec.rb +43 -0
  64. data/spec/br_documents/ie/ap_spec.rb +36 -0
  65. data/spec/br_documents/ie/ba_spec.rb +69 -0
  66. data/spec/br_documents/ie/ce_spec.rb +16 -0
  67. data/spec/br_documents/ie/df_spec.rb +43 -0
  68. data/spec/br_documents/ie/es_spec.rb +16 -0
  69. data/spec/br_documents/ie/factory_spec.rb +202 -0
  70. data/spec/br_documents/ie/go_spec.rb +43 -0
  71. data/spec/br_documents/ie/ma_spec.rb +16 -0
  72. data/spec/br_documents/ie/mg_spec.rb +43 -0
  73. data/spec/br_documents/ie/ms_spec.rb +16 -0
  74. data/spec/br_documents/ie/mt_spec.rb +49 -0
  75. data/spec/br_documents/ie/pa_spec.rb +43 -0
  76. data/spec/br_documents/ie/pb_spec.rb +16 -0
  77. data/spec/br_documents/ie/pe_spec.rb +62 -0
  78. data/spec/br_documents/ie/pi_spec.rb +16 -0
  79. data/spec/br_documents/ie/pr_spec.rb +36 -0
  80. data/spec/br_documents/ie/rj_spec.rb +43 -0
  81. data/spec/br_documents/ie/rn_spec.rb +62 -0
  82. data/spec/br_documents/ie/ro_spec.rb +62 -0
  83. data/spec/br_documents/ie/rr_spec.rb +43 -0
  84. data/spec/br_documents/ie/rs_spec.rb +41 -0
  85. data/spec/br_documents/ie/sc_spec.rb +43 -0
  86. data/spec/br_documents/ie/se_spec.rb +16 -0
  87. data/spec/br_documents/ie/shared_examples_for_pattern1.rb +33 -0
  88. data/spec/br_documents/ie/shared_examples_for_to_remove_all_masks.rb +16 -0
  89. data/spec/br_documents/ie/sp_spec.rb +45 -0
  90. data/spec/br_documents/ie/to_spec.rb +100 -0
  91. data/spec/{ie_validator_spec.rb → br_documents/ie_validator_spec.rb} +12 -9
  92. data/spec/br_documents/suframa_spec.rb +73 -0
  93. data/spec/br_documents/suframa_validator_spec.rb +36 -0
  94. data/spec/spec_helper.rb +6 -6
  95. data/spec/support/utilities.rb +2 -2
  96. metadata +177 -99
  97. data/.circleci/config.yml +0 -42
  98. data/spec/cnpj_cpf/cnpj_spec.rb +0 -59
  99. data/spec/cnpj_cpf/cpf_spec.rb +0 -59
  100. data/spec/cnpj_validator_spec.rb +0 -36
  101. data/spec/cpf_validator_spec.rb +0 -36
  102. data/spec/ie/ac_spec.rb +0 -43
  103. data/spec/ie/al_spec.rb +0 -36
  104. data/spec/ie/am_spec.rb +0 -43
  105. data/spec/ie/ap_spec.rb +0 -36
  106. data/spec/ie/ba_spec.rb +0 -69
  107. data/spec/ie/ce_spec.rb +0 -16
  108. data/spec/ie/df_spec.rb +0 -43
  109. data/spec/ie/es_spec.rb +0 -16
  110. data/spec/ie/factory_spec.rb +0 -203
  111. data/spec/ie/go_spec.rb +0 -43
  112. data/spec/ie/ma_spec.rb +0 -16
  113. data/spec/ie/mg_spec.rb +0 -43
  114. data/spec/ie/ms_spec.rb +0 -16
  115. data/spec/ie/mt_spec.rb +0 -44
  116. data/spec/ie/pa_spec.rb +0 -43
  117. data/spec/ie/pb_spec.rb +0 -16
  118. data/spec/ie/pe_spec.rb +0 -62
  119. data/spec/ie/pi_spec.rb +0 -16
  120. data/spec/ie/pr_spec.rb +0 -36
  121. data/spec/ie/rj_spec.rb +0 -43
  122. data/spec/ie/rn_spec.rb +0 -62
  123. data/spec/ie/ro_spec.rb +0 -62
  124. data/spec/ie/rr_spec.rb +0 -43
  125. data/spec/ie/rs_spec.rb +0 -41
  126. data/spec/ie/sc_spec.rb +0 -43
  127. data/spec/ie/se_spec.rb +0 -16
  128. data/spec/ie/shared_examples_for_pattern1.rb +0 -33
  129. data/spec/ie/shared_examples_for_to_remove_all_masks.rb +0 -17
  130. data/spec/ie/sp_spec.rb +0 -45
  131. data/spec/ie/to_spec.rb +0 -100
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 25cf99032b0bea6b2a016595a560e0a7ea5777154f74d9259009b50323473a61
4
- data.tar.gz: f19aa466afa9077bfbe14184d8311bc7db6486d36d1f73ed855c2b00218a062a
3
+ metadata.gz: 72fc6e3288fa8c5e3b94ddecb5c7488f106ae4108cf9c786b71229fe42b1e9c9
4
+ data.tar.gz: a7cf947a33a61a3f467f433173598a0c8d7dee127872618b80bc5d3e88321904
5
5
  SHA512:
6
- metadata.gz: 3f37a4a5244a984e8ed4bf93077e43dd92caec88ea2e9ee7243b8819c6c520050658d7fdcc3164518a7b324f0e777b78346cbe3e024bc019515e258d251d68a3
7
- data.tar.gz: 67cf2292f3ca90a52ff6790155c6a32382f7c54475b7d572c3fd491f63a756676c88c333f83bd6f961cc97a6fc321df5139c2c7f10881a0af3239bafac313a5c
6
+ metadata.gz: 2ac55324bcf44f94bad987e1100fe659b9150dec1c2d20495b73e4367c4ac65d025dbda3e48183d4ae978e1c75eebeb5149bc293ab464b823af11930f8fbba66
7
+ data.tar.gz: 687d8f399192783ed87b1b75a5cfe07d34e336dae966ee8bcb56eff11010d71c9d8404be20e3674286e8c7c4749f4ffeaab6946fee6e02f608026f966c44d65d
@@ -0,0 +1,40 @@
1
+ name: Tests
2
+
3
+ on: [push]
4
+
5
+ jobs:
6
+ linter:
7
+ runs-on: ubuntu-latest
8
+
9
+ steps:
10
+
11
+ - uses: actions/checkout@v2
12
+
13
+ - uses: ruby/setup-ruby@v1
14
+ with:
15
+ ruby-version: 2.7.3
16
+ bundler-cache: true
17
+
18
+ - run: bundle exec rubocop --display-cop-names --parallel
19
+
20
+ rspec:
21
+ runs-on: ubuntu-latest
22
+
23
+ steps:
24
+ - uses: actions/checkout@v2
25
+
26
+ - uses: ruby/setup-ruby@v1
27
+ with:
28
+ ruby-version: 2.7.3
29
+ bundler-cache: true
30
+
31
+ - run: |
32
+ curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
33
+ chmod +x ./cc-test-reporter
34
+
35
+ - run: |
36
+ ./cc-test-reporter before-build
37
+ bundle exec rspec
38
+ ./cc-test-reporter after-build -r $CC_TEST_REPORTER_ID --exit-code $?
39
+ env:
40
+ CC_TEST_REPORTER_ID: ${{secrets.CC_TEST_REPORTER_ID}}
data/.rubocop.yml ADDED
@@ -0,0 +1,73 @@
1
+ # You can find more information about RuboCop pending cops policy
2
+ # https://docs.rubocop.org/rubocop/versioning.html#pending-cops
3
+ #
4
+ # These are the default options. The .rubocop.yml inherit and
5
+ # override all the default options.
6
+ # https://github.com/rubocop-hq/rubocop/blob/master/config/default.yml
7
+ require:
8
+ - rubocop-rails
9
+ - rubocop-performance
10
+ - rubocop-rspec
11
+ - rubocop-rake
12
+ AllCops:
13
+ TargetRubyVersion: 2.7.3
14
+ DisplayCopNames: true
15
+ DisplayStyleGuide: true
16
+ NewCops: enable
17
+
18
+ # Offense count: 1
19
+ # Configuration parameters: Include.
20
+ # Include: **/*.gemspec
21
+ Gemspec/RequiredRubyVersion:
22
+ Exclude:
23
+ - 'br_documents.gemspec'
24
+
25
+ # Offense count: 1
26
+ # Configuration parameters: Include.
27
+ # Include: **/*.gemspec
28
+ Gemspec/RubyVersionGlobalsUsage:
29
+ Exclude:
30
+ - 'br_documents.gemspec'
31
+
32
+ # Offense count: 1
33
+ # Configuration parameters: IgnoredMethods, CountRepeatedAttributes.
34
+ Metrics/AbcSize:
35
+ Max: 20
36
+
37
+ Metrics/BlockLength:
38
+ Exclude:
39
+ - 'spec/**/*.rb'
40
+
41
+ Style/Documentation:
42
+ Enabled: false
43
+
44
+ RSpec/NamedSubject:
45
+ Enabled: false # default: true
46
+
47
+ RSpec/MultipleExpectations:
48
+ Enabled: false # default: true
49
+
50
+ RSpec/NestedGroups:
51
+ Enabled: false # default: true
52
+
53
+ Style/RegexpLiteral:
54
+ Enabled: false # default: true
55
+
56
+ Style/FrozenStringLiteralComment:
57
+ EnforcedStyle: never # default: always
58
+
59
+ # Offense count: 39
60
+ # Cop supports --auto-correct.
61
+ Style/RedundantRegexpEscape:
62
+ Enabled: false
63
+
64
+ # Offense count: 1
65
+ # Cop supports --auto-correct.
66
+ # Configuration parameters: EnforcedStyle.
67
+ # SupportedStyles: use_perl_names, use_english_names
68
+ Style/SpecialGlobalVars:
69
+ Exclude:
70
+ - 'br_documents.gemspec'
71
+
72
+ Style/WordArray:
73
+ EnforcedStyle: brackets
data/.tool-versions ADDED
@@ -0,0 +1 @@
1
+ ruby 2.7.4
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 CHANGED
@@ -1,54 +1,86 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- br_documents (0.1.3)
4
+ br_documents (0.2.2)
5
5
  activemodel (>= 4.0.0)
6
6
  i18n (>= 0.6.5)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- activemodel (6.0.0)
12
- activesupport (= 6.0.0)
13
- activesupport (6.0.0)
11
+ activemodel (6.1.3.2)
12
+ activesupport (= 6.1.3.2)
13
+ activesupport (6.1.3.2)
14
14
  concurrent-ruby (~> 1.0, >= 1.0.2)
15
- i18n (>= 0.7, < 2)
16
- minitest (~> 5.1)
17
- tzinfo (~> 1.1)
18
- zeitwerk (~> 2.1, >= 2.1.8)
19
- byebug (10.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)
20
21
  codeclimate-test-reporter (1.0.7)
21
22
  simplecov
22
- concurrent-ruby (1.1.5)
23
- diff-lcs (1.3)
24
- docile (1.1.5)
25
- i18n (1.7.0)
23
+ concurrent-ruby (1.1.9)
24
+ diff-lcs (1.4.4)
25
+ docile (1.4.0)
26
+ i18n (1.8.10)
26
27
  concurrent-ruby (~> 1.0)
27
- json (2.0.3)
28
- minitest (5.13.0)
29
- rake (12.0.0)
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.4)
35
- rspec-support (~> 3.5.0)
36
- rspec-expectations (3.5.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.6)
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)
37
44
  diff-lcs (>= 1.2.0, < 2.0)
38
- rspec-support (~> 3.5.0)
39
- rspec-mocks (3.5.0)
45
+ rspec-support (~> 3.10.0)
46
+ rspec-mocks (3.10.2)
40
47
  diff-lcs (>= 1.2.0, < 2.0)
41
- rspec-support (~> 3.5.0)
42
- rspec-support (3.5.0)
43
- simplecov (0.14.0)
44
- docile (~> 1.1.0)
45
- json (>= 1.8, < 3)
46
- simplecov-html (~> 0.10.0)
47
- simplecov-html (0.10.0)
48
- thread_safe (0.3.6)
49
- tzinfo (1.2.6)
50
- thread_safe (~> 0.1)
51
- zeitwerk (2.2.2)
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.4)
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-rake (0.5.1)
69
+ rubocop
70
+ rubocop-rspec (2.3.0)
71
+ rubocop (~> 1.0)
72
+ rubocop-ast (>= 1.1.0)
73
+ ruby-progressbar (1.11.0)
74
+ simplecov (0.21.2)
75
+ docile (~> 1.1)
76
+ simplecov-html (~> 0.11)
77
+ simplecov_json_formatter (~> 0.1)
78
+ simplecov-html (0.12.3)
79
+ simplecov_json_formatter (0.1.3)
80
+ tzinfo (2.0.4)
81
+ concurrent-ruby (~> 1.0)
82
+ unicode-display_width (2.0.0)
83
+ zeitwerk (2.4.2)
52
84
 
53
85
  PLATFORMS
54
86
  ruby
@@ -56,11 +88,16 @@ PLATFORMS
56
88
  DEPENDENCIES
57
89
  br_documents!
58
90
  bundler (>= 1.3)
59
- byebug (= 10.0.2)
60
- codeclimate-test-reporter
61
- rake (>= 10.1.0)
62
- rspec (>= 3.0.0)
63
- simplecov (>= 0.9.0)
91
+ byebug (= 11.1.3)
92
+ codeclimate-test-reporter (>= 1.0.7)
93
+ rake (>= 13.0.3)
94
+ rspec (>= 3.10.0)
95
+ rubocop (~> 1.15.0)
96
+ rubocop-performance (~> 1.11.3)
97
+ rubocop-rails (~> 2.10.1)
98
+ rubocop-rake (>= 0.5.1)
99
+ rubocop-rspec (~> 2.3.0)
100
+ simplecov (>= 0.21.2)
64
101
 
65
102
  BUNDLED WITH
66
- 1.17.2
103
+ 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,6 +170,16 @@ 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
+
150
183
  ## Environment variables
151
184
 
152
185
  The following variables are necessary to be set:
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
- task :console do
9
- sh "irb -rubygems -I lib -r br_documents.rb"
8
+ task console: :enviroment do
9
+ sh 'irb -rubygems -I lib -r br_documents.rb'
10
10
  end
data/br_documents.gemspec CHANGED
@@ -1,30 +1,37 @@
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
 
5
+ # rubocop:disable Metrics/BlockLength
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "br_documents"
7
+ spec.name = 'br_documents'
8
8
  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"
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 '\
13
+ 'or just in ruby.'
14
+ spec.homepage = 'http://github.com/asseinfo/br_documents'
15
+ spec.license = 'MIT'
15
16
 
16
17
  spec.files = `git ls-files`.split($/)
17
18
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
19
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
20
+ spec.require_paths = ['lib']
20
21
 
21
- spec.add_dependency "activemodel", ">= 4.0.0"
22
- spec.add_dependency "i18n", ">= 0.6.5"
22
+ spec.add_dependency 'activemodel', '>= 4.0.0'
23
+ spec.add_dependency 'i18n', '>= 0.6.5'
23
24
 
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", "10.0.2" if RUBY_VERSION >= "2.0"
25
+ spec.add_development_dependency 'bundler', '>= 1.3'
26
+ spec.add_development_dependency 'byebug', '11.1.3' if RUBY_VERSION >= '2.0'
27
+ spec.add_development_dependency 'codeclimate-test-reporter', '>= 1.0.7'
28
+ spec.add_development_dependency 'rake', '>= 13.0.3'
29
+ spec.add_development_dependency 'rspec', '>= 3.10.0'
30
+ spec.add_development_dependency 'rubocop', '~> 1.15.0'
31
+ spec.add_development_dependency 'rubocop-performance', '~> 1.11.3'
32
+ spec.add_development_dependency 'rubocop-rails', '~> 2.10.1'
33
+ spec.add_development_dependency 'rubocop-rake', '>= 0.5.1'
34
+ spec.add_development_dependency 'rubocop-rspec', '~> 2.3.0'
35
+ spec.add_development_dependency 'simplecov', '>= 0.21.2'
30
36
  end
37
+ # rubocop:enable Metrics/BlockLength
@@ -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.chars.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
@@ -1,8 +1,8 @@
1
1
  class CnpjValidator < ActiveModel::EachValidator
2
2
  def validate_each(record, attribute, value)
3
- if value.present?
4
- cnpj = BrDocuments::CnpjCpf::Cnpj.new(value)
5
- record.errors.add(attribute, :invalid) if not cnpj.valid?
6
- end
3
+ return if value.blank?
4
+
5
+ cnpj = BrDocuments::CnpjCpf::Cnpj.new(value)
6
+ record.errors.add(attribute, :invalid) unless cnpj.valid?
7
7
  end
8
8
  end
@@ -1,8 +1,7 @@
1
1
  module BrDocuments
2
2
  module Commons
3
3
  module Mod11
4
-
5
- def generate_digital_check(values, weights)
4
+ def generate_check_digit(values, weights)
6
5
  sum = reduce_weights(values, weights)
7
6
  mod = sum % 11
8
7
  mod < 2 ? 0 : (11 - mod)
@@ -1,8 +1,7 @@
1
1
  module BrDocuments
2
2
  module Commons
3
3
  module Mod14
4
-
5
- def generate_digital_check(values, weights)
4
+ def generate_check_digit(values, weights)
6
5
  sum = reduce_weights(values, weights)
7
6
  mod = sum % 11
8
7
  mod = (11 - mod)
@@ -1,8 +1,8 @@
1
1
  class CpfValidator < ActiveModel::EachValidator
2
2
  def validate_each(record, attribute, value)
3
- if value.present?
4
- cpf = BrDocuments::CnpjCpf::Cpf.new(value)
5
- record.errors.add(attribute, :invalid) if not cpf.valid?
6
- end
3
+ return if value.blank?
4
+
5
+ cpf = BrDocuments::CnpjCpf::Cpf.new(value)
6
+ record.errors.add(attribute, :invalid) unless cpf.valid?
7
7
  end
8
8
  end
@@ -15,14 +15,14 @@ module BrDocuments
15
15
  end
16
16
 
17
17
  def valid_checksum?
18
- numbers = @code.chars[0, @code.length - 1].reverse
18
+ numbers = @code[0, @code.length - 1].chars.reverse
19
19
  odd = even = 0
20
20
 
21
21
  numbers.each_with_index do |number, i|
22
22
  (i + 1).even? ? (even += number.to_i) : (odd += number.to_i * 3)
23
23
  end
24
24
 
25
- @code.chars.last.to_i == ((10 - (odd + even)) % 10)
25
+ @code[-1].to_i == ((10 - (odd + even)) % 10)
26
26
  end
27
27
  end
28
- end
28
+ end
@@ -1,8 +1,8 @@
1
- class GtinValidator < ActiveModel::EachValidator
1
+ class GtinValidator < ActiveModel::EachValidator
2
2
  def validate_each(record, attribute, value)
3
- if value.present?
4
- gtin = BrDocuments::Gtin.new(value)
5
- record.errors.add(attribute, :invalid) if not gtin.valid?
6
- end
3
+ return if value.blank?
4
+
5
+ gtin = BrDocuments::Gtin.new(value)
6
+ record.errors.add(attribute, :invalid) unless gtin.valid?
7
7
  end
8
- end
8
+ end
@@ -1,4 +1,4 @@
1
- require_relative "pattern2"
1
+ require_relative 'pattern2'
2
2
 
3
3
  module BrDocuments
4
4
  module IE
@@ -9,8 +9,9 @@ module BrDocuments
9
9
  end
10
10
 
11
11
  private
12
+
12
13
  def format_ie(number)
13
- number.sub(/(\d{2})(\d{3})(\d{3})(\d{3})(\d{2})/, "\\1.\\2.\\3/\\4-\\5")
14
+ number.sub(/(\d{2})(\d{3})(\d{3})(\d{3})(\d{2})/, '\\1.\\2.\\3/\\4-\\5')
14
15
  end
15
16
  end
16
17
  end
@@ -1,4 +1,4 @@
1
- require_relative "pattern1"
1
+ require_relative 'pattern1'
2
2
 
3
3
  module BrDocuments
4
4
  module IE
@@ -9,6 +9,7 @@ module BrDocuments
9
9
  end
10
10
 
11
11
  private
12
+
12
13
  def format_ie(number)
13
14
  number
14
15
  end
@@ -1,4 +1,4 @@
1
- require_relative "pattern1"
1
+ require_relative 'pattern1'
2
2
 
3
3
  module BrDocuments
4
4
  module IE
@@ -9,8 +9,9 @@ module BrDocuments
9
9
  end
10
10
 
11
11
  private
12
+
12
13
  def format_ie(number)
13
- number.sub(/(\d{2})(\d{3})(\d{3})(\d{1})/, "\\1.\\2.\\3-\\4")
14
+ number.sub(/(\d{2})(\d{3})(\d{3})(\d{1})/, '\\1.\\2.\\3-\\4')
14
15
  end
15
16
  end
16
17
  end