br_documents 0.2.3 → 0.2.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a893a246eb1c07b45241c0eec46268a58a01aa7e2bbb0f02f8294e3c1f6c0ccf
4
- data.tar.gz: 8ad80b4d402567412752ed48eab9c0adec82fa6d92cf8dcf6bfbf788e72e8a6b
3
+ metadata.gz: 91d2ac26c3f7fa33806675aa10ca8d08b6d276983724e373a872ab5540ea369c
4
+ data.tar.gz: 2ce24db58349653730f9338e16bda7b96459bb3670f21fb7383dbf9e6ce498be
5
5
  SHA512:
6
- metadata.gz: 43d5217a448c6ed1297084b59c4935021a0bfda1968be33b109985cd169ea80b435adaec30373ba84b3125828842e7cce71033e3f7d842db3af0610f2c0e87d0
7
- data.tar.gz: 63538e8845f2143637a685af12b944cc37c2b5ecb34fc32f3eb67c859cbd28968daaadac4669146322794e2029a0a0034c9fbdf94a90dcf887a309e125ca4e7d
6
+ metadata.gz: 7f2a2eedad3ce0394be82a13f019f0236044992e9e87f63a933889e99ff9e282a8b3c6e561520c22de4e6e3311b88fa7772b89c94e8955baf564683a0190e44a
7
+ data.tar.gz: c03ce1f4d3c38ccf37b11a8ae725f0b7478fe9aae4124c7c2cb84d116d93878d2de451146f854e6e191406ec8a6e1ab63295013366a89d775c68bfa24a149669
@@ -0,0 +1,16 @@
1
+ # To get started with Dependabot version updates, you'll need to specify which
2
+ # package ecosystems to update and where the package manifests are located.
3
+ # Please see the documentation for all configuration options:
4
+ # https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5
+
6
+ version: 2
7
+ updates:
8
+ - package-ecosystem: "" # See documentation for possible values
9
+ directory: "/" # Location of package manifests
10
+ schedule:
11
+ interval: "monthly"
12
+ open-pull-requests-limit: 10
13
+ allow:
14
+ - dependency-type: "direct"
15
+ pull-request-branch-name:
16
+ separator: "-"
@@ -12,7 +12,7 @@ jobs:
12
12
 
13
13
  - uses: ruby/setup-ruby@v1
14
14
  with:
15
- ruby-version: 2.7.3
15
+ ruby-version: 3.0.4
16
16
  bundler-cache: true
17
17
 
18
18
  - run: bundle exec rubocop --display-cop-names --parallel
@@ -25,7 +25,7 @@ jobs:
25
25
 
26
26
  - uses: ruby/setup-ruby@v1
27
27
  with:
28
- ruby-version: 2.7.3
28
+ ruby-version: 3.0.4
29
29
  bundler-cache: true
30
30
 
31
31
  - run: |
data/.rubocop.yml CHANGED
@@ -37,6 +37,7 @@ Metrics/AbcSize:
37
37
  Metrics/BlockLength:
38
38
  Exclude:
39
39
  - 'spec/**/*.rb'
40
+ - 'br_documents.gemspec'
40
41
 
41
42
  Style/Documentation:
42
43
  Enabled: false
@@ -50,6 +51,9 @@ RSpec/MultipleExpectations:
50
51
  RSpec/NestedGroups:
51
52
  Enabled: false # default: true
52
53
 
54
+ RSpec/ExampleLength:
55
+ Enabled: false # default: true
56
+
53
57
  Style/RegexpLiteral:
54
58
  Enabled: false # default: true
55
59
 
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- br_documents (0.2.3)
4
+ br_documents (0.2.5)
5
5
  activemodel (>= 4.0.0)
6
6
  i18n (>= 0.6.5)
7
7
 
@@ -29,7 +29,7 @@ GEM
29
29
  parallel (1.20.1)
30
30
  parser (3.0.1.1)
31
31
  ast (~> 2.4.1)
32
- rack (2.2.3)
32
+ rack (3.0.0)
33
33
  rainbow (3.0.0)
34
34
  rake (13.0.6)
35
35
  regexp_parser (2.1.1)
data/README.md CHANGED
@@ -193,7 +193,12 @@ RAILS_ENV | no | no | yes | no | test
193
193
 
194
194
  ## Deploy to Rubygems
195
195
 
196
- $ bundle exec rake release # Create tag vX.X.X, build and push br_documents-X.X.X.gem to Rubygems
196
+ 1. Increment the version `lib/br_documents/version.rb` and commit
197
+ 2. Run
198
+
199
+ ```
200
+ $ bundle exec rake release # Create tag vX.X.X, build and push br_documents-X.X.X.gem to Rubygems
201
+ ```
197
202
 
198
203
  You can build or install using one of the above tasks
199
204
 
data/br_documents.gemspec CHANGED
@@ -2,7 +2,6 @@ lib = File.expand_path('lib', __dir__)
2
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
  require 'br_documents/version'
4
4
 
5
- # rubocop:disable Metrics/BlockLength
6
5
  Gem::Specification.new do |spec|
7
6
  spec.name = 'br_documents'
8
7
  spec.version = BrDocuments::VERSION
@@ -34,4 +33,3 @@ Gem::Specification.new do |spec|
34
33
  spec.add_development_dependency 'rubocop-rspec', '~> 2.3.0'
35
34
  spec.add_development_dependency 'simplecov', '>= 0.21.2'
36
35
  end
37
- # rubocop:enable Metrics/BlockLength
@@ -6,6 +6,10 @@ module BrDocuments
6
6
  class AP < Base
7
7
  include Commons::Mod11
8
8
 
9
+ def valid?
10
+ @number.to_s.size == 9 && super
11
+ end
12
+
9
13
  protected
10
14
 
11
15
  def format_ie(number)
@@ -18,6 +22,8 @@ module BrDocuments
18
22
  end
19
23
 
20
24
  def valid_check_digit?
25
+ return false if number_to_calculate_digits < 3_000_001
26
+
21
27
  weight = [9, 8, 7, 6, 5, 4, 3, 2]
22
28
  detect_range_digits
23
29
  @number[-1] == generate_check_digit(@number, weight).to_s
@@ -27,7 +33,7 @@ module BrDocuments
27
33
 
28
34
  # rubocop:disable Metrics/MethodLength
29
35
  def detect_range_digits
30
- number = @number[0, 8].to_i
36
+ number = number_to_calculate_digits
31
37
 
32
38
  if number >= 3_000_001 && number <= 3_017_000
33
39
  @p = 5
@@ -42,6 +48,10 @@ module BrDocuments
42
48
  end
43
49
  # rubocop:enable Metrics/MethodLength
44
50
 
51
+ def number_to_calculate_digits
52
+ @number[0, 8].to_i
53
+ end
54
+
45
55
  def generate_check_digit(values, weights)
46
56
  sum = reduce_weights(values, weights)
47
57
  sum += @p
@@ -1,3 +1,3 @@
1
1
  module BrDocuments
2
- VERSION = '0.2.3'.freeze
2
+ VERSION = '0.2.5'.freeze
3
3
  end
@@ -11,7 +11,7 @@ RSpec.describe BrDocuments::IE::AP do
11
11
 
12
12
  describe '#valid?' do
13
13
  it 'is invalid with length different to 9' do
14
- ['1234567', '123456789012'].each do |number|
14
+ ['12345678', '1234567890'].each do |number|
15
15
  ie = described_class.new(number)
16
16
  expect(ie).not_to be_valid
17
17
  end
@@ -24,13 +24,27 @@ RSpec.describe BrDocuments::IE::AP do
24
24
  end
25
25
  end
26
26
 
27
- it 'is valid with valid number' do
28
- ['030123459', '030183458', '030213452', '030213460'].each do |number|
27
+ it 'is invalid if the number is less than 3_000_001' do
28
+ ['030000000', '000000000'].each do |number|
29
29
  ie = described_class.new(number)
30
- expect(ie).to be_valid
30
+ expect(ie).not_to be_valid
31
31
  end
32
32
  end
33
33
 
34
+ it 'is valid with valid number' do
35
+ first_range_number = '030000012'
36
+ ie = described_class.new(first_range_number)
37
+ expect(ie).to be_valid
38
+
39
+ second_range_number = '030170011'
40
+ ie = described_class.new(second_range_number)
41
+ expect(ie).to be_valid
42
+
43
+ third_range_number = '030190231'
44
+ ie = described_class.new(third_range_number)
45
+ expect(ie).to be_valid
46
+ end
47
+
34
48
  include_examples 'for to remove all masks', '030213452'
35
49
  end
36
50
  end
@@ -195,7 +195,7 @@ describe BrDocuments::IE::Factory do
195
195
  it 'is returns an error' do
196
196
  expect do
197
197
  described_class.create('', '')
198
- end.to raise_error(ArgumentError, t('validator.ie.uf.invalid'))
198
+ end.to raise_error(ArgumentError, I18n.t('validator.ie.uf.invalid'))
199
199
  end
200
200
  end
201
201
  end
@@ -55,7 +55,7 @@ RSpec.describe IeValidator do
55
55
  end
56
56
 
57
57
  it 'adds error in model' do
58
- expect(record.errors.messages['ie']).to include t('validator.ie.uf.invalid')
58
+ expect(record.errors.messages['ie']).to include I18n.t('validator.ie.uf.invalid')
59
59
  end
60
60
  end
61
61
 
@@ -66,9 +66,7 @@ RSpec.describe IeValidator do
66
66
  end
67
67
 
68
68
  it 'adds error in model' do
69
- expect(record.errors.messages[:base]).to eql [
70
- t('validator.ie.uf.no_present', uf: 'uf')
71
- ]
69
+ expect(record.errors.messages[:base]).to eql [I18n.t('validator.ie.uf.no_present', uf: 'uf')]
72
70
  end
73
71
  end
74
72
 
@@ -78,9 +76,7 @@ RSpec.describe IeValidator do
78
76
  before { subject.validate_each(record, 'ie', '253667852') }
79
77
 
80
78
  it 'adds error in model' do
81
- expect(record.errors.messages[:base]).to eql [
82
- t('validator.ie.uf.no_configured')
83
- ]
79
+ expect(record.errors.messages[:base]).to eql [I18n.t('validator.ie.uf.no_configured')]
84
80
  end
85
81
  end
86
82
  end
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require 'simplecov'
2
- SimpleCov.start
2
+ SimpleCov.start unless ENV['NO_COVERAGE']
3
3
 
4
4
  require 'bundler/setup'
5
5
  Bundler.require(:default, :development)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: br_documents
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - ASSEINFO - Sistemas de Informação
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-08-25 00:00:00.000000000 Z
11
+ date: 2022-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -199,11 +199,11 @@ executables: []
199
199
  extensions: []
200
200
  extra_rdoc_files: []
201
201
  files:
202
+ - ".github/dependabot.yml"
202
203
  - ".github/workflows/config.yml"
203
204
  - ".gitignore"
204
205
  - ".rspec"
205
206
  - ".rubocop.yml"
206
- - ".tool-versions"
207
207
  - Gemfile
208
208
  - Gemfile.lock
209
209
  - README.md
@@ -295,7 +295,6 @@ files:
295
295
  - spec/br_documents/suframa_spec.rb
296
296
  - spec/br_documents/suframa_validator_spec.rb
297
297
  - spec/spec_helper.rb
298
- - spec/support/utilities.rb
299
298
  homepage: http://github.com/asseinfo/br_documents
300
299
  licenses:
301
300
  - MIT
@@ -315,7 +314,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
315
314
  - !ruby/object:Gem::Version
316
315
  version: '0'
317
316
  requirements: []
318
- rubygems_version: 3.1.6
317
+ rubygems_version: 3.2.33
319
318
  signing_key:
320
319
  specification_version: 4
321
320
  summary: Validates brazilian documents like CPF, CNPJ and IE. It can be used with
@@ -361,4 +360,3 @@ test_files:
361
360
  - spec/br_documents/suframa_spec.rb
362
361
  - spec/br_documents/suframa_validator_spec.rb
363
362
  - spec/spec_helper.rb
364
- - spec/support/utilities.rb
data/.tool-versions DELETED
@@ -1 +0,0 @@
1
- ruby 2.7.4
@@ -1,3 +0,0 @@
1
- def t(string, options = {})
2
- I18n.t(string, options)
3
- end