bra_documents 1.1.0 → 1.1.1

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: 5edcee719c06808ad9d7a4bb17c38aac505275489576e0864bc7ac85dcf1541d
4
- data.tar.gz: 9f86a8ff44a78bab3e2a82c93c7107667c78baafc683fecb81345ec2060c6df7
3
+ metadata.gz: 9abb59173a8af173e52415a22f9f0931c2d02fbe1bf710b7a4039fb7e7a896c6
4
+ data.tar.gz: d1cb2ec1282cb184b55f05c99bdb311a118ffbe7f53c649b676bdc0d44e00fe6
5
5
  SHA512:
6
- metadata.gz: 289d2e3fefb83ef555f8e64c85301c17c3262361ffc984be09111181c481edd235000d0ad5bd438afed6909d046ff9c4533fa07db1148857312bd8dc6381d92a
7
- data.tar.gz: 02c03f625084618ffc291f2d5257ecd84af8ba942a884f1abaf8b99730360be3e6c151a13e033dbd81445ddbe42280e9c0f0534e1dcf06cf36ef6c3ac142fe9f
6
+ metadata.gz: 6d374d7c23a9d5e509dc8fe2510e14c5014a9078b9417c4928a74888c44f62d2ffabf9827f9458c5c2af2b83e292e86dd956b838d4aec11f7edc82e2f8ddd402
7
+ data.tar.gz: bc2a922081d085404263c3fd91a1072ce1fc8098a5efaddcab08d2b1e092ce369160928a561d9552f37e6da946e24422b01361d5ba781e9728b86f014aa44d15
data/CHANGELOG.md CHANGED
@@ -1,12 +1,15 @@
1
-
2
1
  # Changelog
3
2
 
4
3
  All notable changes to this project will be documented in this file.
5
4
 
6
- The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
7
- and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
5
+ This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [1.1.1](https://github.com/bvicenzo/bra_documents/compare/v1.1.0...v1.1.1) (2026-12-01)
8
+
9
+
10
+ ### Bug Fixes
8
11
 
9
- ## [Unreleased]
12
+ * reject formatted CPFs with all digits equal ([#38](https://github.com/bvicenzo/bra_documents/pull/38)) ([400c1c7](https://github.com/bvicenzo/bra_documents/commit/400c1c77d0a40d300e6e8d8eb0bbd08fe9127036)), closes [#36](https://github.com/bvicenzo/bra_documents/issues/36)
10
13
 
11
14
  ## [1.1.0] - 2026-01-14
12
15
 
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # BraDocuments
2
2
 
3
- [![Build Status](https://travis-ci.com/bvicenzo/bra_documents.svg?branch=master)](https://travis-ci.com/bvicenzo/bra_documents)
3
+ [![Ruby](https://github.com/bvicenzo/bra_documents/actions/workflows/main.yml/badge.svg)](https://github.com/bvicenzo/bra_documents/actions/workflows/main.yml)
4
4
 
5
5
  This gem make us able to generate Brazilian documents, such as CPF and CNPJ.
6
6
  We can generate a tottaly random number, or pass the number and the gem completes with the verification digits.
@@ -13,7 +13,7 @@ If you already have a CPF or CNPJ only their numbers, you can also put the mask
13
13
  Add this line to your application's Gemfile:
14
14
 
15
15
  ```ruby
16
- gem 'bra_documents'
16
+ gem 'bra_documents', '~> 1.1'
17
17
  ```
18
18
 
19
19
  And then execute:
@@ -226,13 +226,19 @@ end
226
226
 
227
227
  ## Development
228
228
 
229
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
229
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec rake` to run the tests and RuboCop. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
230
230
 
231
- 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).
231
+ To install this gem onto your local machine, run `bundle exec rake install`.
232
+
233
+ Releases are automated: the version, the `CHANGELOG.md`, the git tag and the push
234
+ to [rubygems.org](https://rubygems.org) are all derived from
235
+ [Conventional Commits](https://www.conventionalcommits.org/) by release-please.
236
+ There is no version to edit and no release command to run by hand — see
237
+ [CONTRIBUTING.md](CONTRIBUTING.md).
232
238
 
233
239
  ## Contributing
234
240
 
235
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/bra_documents.
241
+ Bug reports and pull requests are welcome on GitHub at https://github.com/bvicenzo/bra_documents. Read [CONTRIBUTING.md](CONTRIBUTING.md) first — it covers the commit conventions the release automation depends on.
236
242
 
237
243
 
238
244
  ## License
@@ -46,7 +46,7 @@ module BraDocuments
46
46
 
47
47
  full_number = complete!(numbers)
48
48
 
49
- formatted ? Formatter.format(full_number, as: :cnpj) : full_number
49
+ formatted ? Formatter.format(full_number, as: :cnpj) : full_number
50
50
  end
51
51
 
52
52
  # Returns if a CPF has a valid verification digit.
@@ -61,7 +61,7 @@ module BraDocuments
61
61
  # # => true
62
62
  def valid_verification_digit?(document:)
63
63
  raw_document = Formatter.raw(document, kind: :cnpj)
64
- return false if !Matcher.match?(raw_document, kind: :cnpj, mode: :raw)
64
+ return false unless Matcher.match?(raw_document, kind: :cnpj, mode: :raw)
65
65
 
66
66
  company_number = raw_document.slice(0..(COMPANY_NUMBER_SIZE - 1))
67
67
  matrix_subsidiary_number = raw_document
@@ -75,7 +75,7 @@ module BraDocuments
75
75
  private
76
76
 
77
77
  def number_with(size)
78
- size.times.map { ALPHANUM_UPPER.sample }
78
+ Array.new(size) { ALPHANUM_UPPER.sample }
79
79
  end
80
80
 
81
81
  def verification_digit_multiplicators_for(numbers)
@@ -41,7 +41,7 @@ module BraDocuments
41
41
  # # => true
42
42
  def valid_verification_digit?(document:)
43
43
  raw_document = Formatter.raw(document)
44
- return false if !Matcher.match?(raw_document, kind: :cpf, mode: :raw)
44
+ return false unless Matcher.match?(raw_document, kind: :cpf, mode: :raw)
45
45
 
46
46
  person_number = raw_document.slice(0..(PERSON_NUMBER_SIZE - 1))
47
47
  verified_digit = raw_document.slice(PERSON_NUMBER_SIZE..(raw_document.size - 1))
@@ -52,7 +52,7 @@ module BraDocuments
52
52
  private
53
53
 
54
54
  def number_with(size)
55
- size.times.map { rand(10) }
55
+ Array.new(size) { rand(10) }
56
56
  end
57
57
 
58
58
  def verification_digit_multiplicators_for(numbers)
@@ -5,28 +5,27 @@ module BraDocuments
5
5
  FORMATS = {
6
6
  cpf: {
7
7
  raw: /\A(?!([0-9])\1{10})\d{11}\z/,
8
- formatted: /\A(?!([0-9])(?:[.\-]?\1){10}[.\-]?\d{2})(\d{3}\.){2}\d{3}-\d{2}\z/
8
+ formatted: /\A(?!([0-9])(?:[.-]?\1){10}\z)(\d{3}\.){2}\d{3}-\d{2}\z/
9
9
  },
10
10
  cnpj: {
11
11
  raw: /\A(?!([A-Z0-9])\1{11}\d{2})[A-Z0-9]{12}\d{2}\z/i,
12
- formatted: /
12
+ formatted: %r{
13
13
  \A
14
14
  (?! # disallow all characters being the same
15
15
  ([A-Z0-9])
16
- (?: [.\-\/]? \1 ){11}
17
- [.\-\/]? \d{2}
16
+ (?: [.\-/]? \1 ){11}
17
+ [.\-/]? \d{2}
18
18
  )
19
19
  [A-Z0-9]{2} \.
20
20
  [A-Z0-9]{3} \.
21
- [A-Z0-9]{3} \/
21
+ [A-Z0-9]{3} /
22
22
  [A-Z0-9]{4} -
23
23
  \d{2}
24
24
  \z
25
- /ix
25
+ }ix
26
26
  }
27
27
  }.freeze
28
28
 
29
-
30
29
  class << self
31
30
  # Macthes with Brazilian CPF and CNPJ documents.
32
31
  #
@@ -36,7 +35,7 @@ module BraDocuments
36
35
  # BraDocuments::Matcher.match?('12345678888', kind: :cpf, mode: :raw)
37
36
  # # => true
38
37
  #
39
- # BraDocuments::Matcher.match?('11111111111', kind: :cpf, mode: :formatted)
38
+ # BraDocuments::Matcher.match?('111.111.111-11', kind: :cpf, mode: :formatted)
40
39
  # # => false
41
40
  #
42
41
  # BraDocuments::Matcher.match?('11111111111111', kind: :cnpj, mode: :raw)
@@ -63,11 +62,17 @@ module BraDocuments
63
62
  raise ArgumentError, "\"#{number.inspect}\" must be a String." unless number.is_a?(String)
64
63
 
65
64
  unless known_format?(kind)
66
- raise ArgumentError, "Unknown document kind \"#{kind.inspect}\". Known documents: #{known_formats.join(', ')}."
65
+ raise(
66
+ ArgumentError,
67
+ "Unknown document kind \"#{kind.inspect}\". Known documents: #{known_formats.join(', ')}."
68
+ )
67
69
  end
68
70
 
69
71
  unless known_mode?(mode)
70
- raise ArgumentError, "Unknown document format mode \"#{mode.inspect}\". Known modes: #{known_modes.join(', ')}."
72
+ raise(
73
+ ArgumentError,
74
+ "Unknown document format mode \"#{mode.inspect}\". Known modes: #{known_modes.join(', ')}."
75
+ )
71
76
  end
72
77
 
73
78
  formats_to_match(kind, mode).any? { |format| format.match?(number) }
@@ -15,14 +15,14 @@ module BraDocuments
15
15
 
16
16
  def number_for(number_description, number_size, given_value, kind:)
17
17
  given_value = Formatter.raw(given_value.to_s, kind:)
18
- if !given_value.to_s.empty?
18
+ if given_value.to_s.empty?
19
+ number_with(number_size)
20
+ else
19
21
  unless given_value.size == number_size
20
22
  raise ArgumentError, "#{number_description} number must be a number with #{number_size} digits."
21
23
  end
22
24
 
23
- given_value.split('')
24
- else
25
- number_with(number_size)
25
+ given_value.chars
26
26
  end
27
27
  end
28
28
 
@@ -6,7 +6,7 @@ RSpec::Matchers.define :a_formatted_cnpj do
6
6
  match { |cnpj| BraDocuments::Matcher.match?(cnpj.to_s, kind: :cnpj, mode: :formatted) }
7
7
 
8
8
  failure_message do |cnpj|
9
- "Was expected `#{cnpj.inspect}` to be a Brazilian CNPJ document number but it isn't.\n"\
9
+ "Was expected `#{cnpj.inspect}` to be a Brazilian CNPJ document number but it isn't.\n" \
10
10
  "A CNPJ has the following format AA.AAA.AAA/AAAA-99 where X are numbers from 0 to 9.\n"
11
11
  end
12
12
  end
@@ -15,7 +15,7 @@ RSpec::Matchers.define :a_raw_cnpj do
15
15
  match { |cnpj| BraDocuments::Matcher.match?(cnpj.to_s, kind: :cnpj, mode: :raw) }
16
16
 
17
17
  failure_message do |cnpj|
18
- "Was expected `#{cnpj.inspect}` to be a raw Brazilian cnpj document number but it isn't.\n"\
18
+ "Was expected `#{cnpj.inspect}` to be a raw Brazilian cnpj document number but it isn't.\n" \
19
19
  "A raw CNPJ has the following format AAAAAAAAAAAAAA where X are numbers from 0 to 9.\n"
20
20
  end
21
21
  end
@@ -6,7 +6,7 @@ RSpec::Matchers.define :a_formatted_cpf do
6
6
  match { |cpf| BraDocuments::Matcher.match?(cpf.to_s, kind: :cpf, mode: :formatted) }
7
7
 
8
8
  failure_message do |cpf|
9
- "Was expected `#{cpf.inspect}` to be a Brazilian CPF document number but it isn't.\n"\
9
+ "Was expected `#{cpf.inspect}` to be a Brazilian CPF document number but it isn't.\n" \
10
10
  "A CPF has the following format 999.999.999-99 where X are numbers from 0 to 9.\n"
11
11
  end
12
12
  end
@@ -15,7 +15,7 @@ RSpec::Matchers.define :a_raw_cpf do
15
15
  match { |cpf| BraDocuments::Matcher.match?(cpf.to_s, kind: :cpf, mode: :raw) }
16
16
 
17
17
  failure_message do |cpf|
18
- "Was expected `#{cpf.inspect}` to be a raw Brazilian CPF document number but it isn't.\n"\
18
+ "Was expected `#{cpf.inspect}` to be a raw Brazilian CPF document number but it isn't.\n" \
19
19
  "A raw CPF has the following format XXXXXXXXXXX where X are numbers from 0 to 9.\n"
20
20
  end
21
21
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BraDocuments
4
- VERSION = '1.1.0'
4
+ VERSION = '1.1.1'
5
5
  end
metadata CHANGED
@@ -1,56 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bra_documents
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bruno Vicenzo
8
- bindir: exe
8
+ bindir: bin
9
9
  cert_chain: []
10
10
  date: 1980-01-02 00:00:00.000000000 Z
11
- dependencies:
12
- - !ruby/object:Gem::Dependency
13
- name: rake
14
- requirement: !ruby/object:Gem::Requirement
15
- requirements:
16
- - - ">="
17
- - !ruby/object:Gem::Version
18
- version: '0'
19
- type: :development
20
- prerelease: false
21
- version_requirements: !ruby/object:Gem::Requirement
22
- requirements:
23
- - - ">="
24
- - !ruby/object:Gem::Version
25
- version: '0'
26
- - !ruby/object:Gem::Dependency
27
- name: rspec
28
- requirement: !ruby/object:Gem::Requirement
29
- requirements:
30
- - - ">="
31
- - !ruby/object:Gem::Version
32
- version: '0'
33
- type: :development
34
- prerelease: false
35
- version_requirements: !ruby/object:Gem::Requirement
36
- requirements:
37
- - - ">="
38
- - !ruby/object:Gem::Version
39
- version: '0'
40
- - !ruby/object:Gem::Dependency
41
- name: irb
42
- requirement: !ruby/object:Gem::Requirement
43
- requirements:
44
- - - ">="
45
- - !ruby/object:Gem::Version
46
- version: '0'
47
- type: :development
48
- prerelease: false
49
- version_requirements: !ruby/object:Gem::Requirement
50
- requirements:
51
- - - ">="
52
- - !ruby/object:Gem::Version
53
- version: '0'
11
+ dependencies: []
54
12
  description: Here we are able to generate CPNJ and CPF documents, only numbers or
55
13
  formatted.
56
14
  email:
@@ -59,25 +17,9 @@ executables: []
59
17
  extensions: []
60
18
  extra_rdoc_files: []
61
19
  files:
62
- - ".github/dependabot.yml"
63
- - ".github/workflows/main.yml"
64
- - ".gitignore"
65
- - ".mise.toml"
66
- - ".rspec"
67
- - ".travis.yml"
68
20
  - CHANGELOG.md
69
- - Gemfile
70
- - Gemfile.lock
71
- - LICENSE
72
21
  - LICENSE.txt
73
22
  - README.md
74
- - Rakefile
75
- - bin/console
76
- - bin/rake
77
- - bin/rdoc
78
- - bin/rspec
79
- - bin/setup
80
- - bra_documents.gemspec
81
23
  - lib/bra_documents.rb
82
24
  - lib/bra_documents/cnpj_generator.rb
83
25
  - lib/bra_documents/cpf_generator.rb
@@ -92,10 +34,11 @@ homepage: https://github.com/bvicenzo/bra_documents
92
34
  licenses:
93
35
  - MIT
94
36
  metadata:
95
- allowed_push_host: https://rubygems.org/
37
+ allowed_push_host: https://rubygems.org
96
38
  homepage_uri: https://github.com/bvicenzo/bra_documents
97
39
  source_code_uri: https://github.com/bvicenzo/bra_documents
98
40
  changelog_uri: https://github.com/bvicenzo/bra_documents/blob/master/CHANGELOG.md
41
+ rubygems_mfa_required: 'true'
99
42
  rdoc_options: []
100
43
  require_paths:
101
44
  - lib
@@ -110,7 +53,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
110
53
  - !ruby/object:Gem::Version
111
54
  version: '0'
112
55
  requirements: []
113
- rubygems_version: 4.0.3
56
+ rubygems_version: 4.0.20
114
57
  specification_version: 4
115
58
  summary: A implementation for generating Brazilian CPF and CNPJ document numbers.
116
59
  test_files: []
@@ -1,8 +0,0 @@
1
- version: 2
2
- updates:
3
- - package-ecosystem: bundler
4
- directory: "/"
5
- schedule:
6
- interval: daily
7
- time: "09:00"
8
- open-pull-requests-limit: 10
@@ -1,29 +0,0 @@
1
- name: Ruby
2
-
3
- on:
4
- push:
5
- branches:
6
- - master
7
-
8
- pull_request:
9
-
10
- jobs:
11
- build:
12
- runs-on: ubuntu-latest
13
- name: Ruby ${{ matrix.ruby }}
14
- strategy:
15
- matrix:
16
- ruby:
17
- - '3.3.7'
18
- - '3.4.2'
19
- - '4.0.0'
20
-
21
- steps:
22
- - uses: actions/checkout@v5
23
- - name: Set up Ruby
24
- uses: ruby/setup-ruby@v1
25
- with:
26
- ruby-version: ${{ matrix.ruby }}
27
- bundler-cache: true
28
- - name: Run the default task
29
- run: bundle exec rake
data/.gitignore DELETED
@@ -1,11 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /_yardoc/
4
- /coverage/
5
- /doc/
6
- /pkg/
7
- /spec/reports/
8
- /tmp/
9
-
10
- # rspec failure tracking
11
- .rspec_status
data/.mise.toml DELETED
@@ -1,2 +0,0 @@
1
- [tools]
2
- ruby = "4.0.0"
data/.rspec DELETED
@@ -1,3 +0,0 @@
1
- --format documentation
2
- --color
3
- --require spec_helper
data/.travis.yml DELETED
@@ -1,12 +0,0 @@
1
- ---
2
- language: ruby
3
- cache: bundler
4
- rvm:
5
- - 2.7.2
6
- - 2.6.6
7
- - 2.5.8
8
- - 2.4.10
9
- - 3.0.3
10
- - 3.1.1
11
-
12
- before_install: gem install bundler -v 2.1.4
data/Gemfile DELETED
@@ -1,6 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source "https://rubygems.org"
4
-
5
- # Specify your gem's dependencies in bra_documents.gemspec
6
- gemspec
data/Gemfile.lock DELETED
@@ -1,57 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- bra_documents (1.1.0)
5
-
6
- GEM
7
- remote: https://rubygems.org/
8
- specs:
9
- date (3.5.1)
10
- diff-lcs (1.6.2)
11
- erb (6.0.1)
12
- io-console (0.8.2)
13
- irb (1.16.0)
14
- pp (>= 0.6.0)
15
- rdoc (>= 4.0.0)
16
- reline (>= 0.4.2)
17
- pp (0.6.3)
18
- prettyprint
19
- prettyprint (0.2.0)
20
- psych (5.3.1)
21
- date
22
- stringio
23
- rake (13.3.1)
24
- rdoc (7.1.0)
25
- erb
26
- psych (>= 4.0.0)
27
- tsort
28
- reline (0.6.3)
29
- io-console (~> 0.5)
30
- rspec (3.13.2)
31
- rspec-core (~> 3.13.0)
32
- rspec-expectations (~> 3.13.0)
33
- rspec-mocks (~> 3.13.0)
34
- rspec-core (3.13.6)
35
- rspec-support (~> 3.13.0)
36
- rspec-expectations (3.13.5)
37
- diff-lcs (>= 1.2.0, < 2.0)
38
- rspec-support (~> 3.13.0)
39
- rspec-mocks (3.13.7)
40
- diff-lcs (>= 1.2.0, < 2.0)
41
- rspec-support (~> 3.13.0)
42
- rspec-support (3.13.6)
43
- stringio (3.2.0)
44
- tsort (0.2.0)
45
-
46
- PLATFORMS
47
- ruby
48
- x86_64-darwin-24
49
-
50
- DEPENDENCIES
51
- bra_documents!
52
- irb
53
- rake
54
- rspec
55
-
56
- BUNDLED WITH
57
- 4.0.3