cpf_cnpj_tools 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.idea/cpf_cnpj_tools.iml +70 -0
- data/.idea/modules.xml +8 -0
- data/.idea/vcs.xml +6 -0
- data/.idea/workspace.xml +69 -0
- data/.rubocop.yml +13 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/Gemfile +12 -0
- data/LICENSE.txt +21 -0
- data/README.md +42 -0
- data/Rakefile +16 -0
- data/cpf_cnpj_tools.gemspec +37 -0
- data/lib/cpf_cnpj_tools/version.rb +5 -0
- data/lib/cpf_cnpj_tools.rb +123 -0
- data/sig/cpf_cnpj_tools.rbs +4 -0
- metadata +62 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 453f4b1f02a4e86f772a4428fb4f3389c7d44ca0fa339cf0b8e6a118e20040e2
|
4
|
+
data.tar.gz: cd9e84c7688720635aa3e0348d1e87c7fe29896c56f764714e53ae3ffcf85154
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: be6f5f87ab65347f711824e01eb045ac14f82dd47f4a5d0d150d161f6372b4e316fe565917ee390cc46701ebb529e368173246bd16aee5abd752ebf02adc013d
|
7
|
+
data.tar.gz: 316a53c10f44f4752ba0a25c623a6d51c8e2426bfc0735c964ff69eefda8bfefb80785dc904819cb2b10fd1aafc6aa7a55638875d0bf548d7ac43ba51348a651
|
@@ -0,0 +1,70 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<module type="RUBY_MODULE" version="4">
|
3
|
+
<component name="ModuleRunConfigurationManager">
|
4
|
+
<shared />
|
5
|
+
</component>
|
6
|
+
<component name="NewModuleRootManager">
|
7
|
+
<content url="file://$MODULE_DIR$">
|
8
|
+
<sourceFolder url="file://$MODULE_DIR$/features" isTestSource="true" />
|
9
|
+
<sourceFolder url="file://$MODULE_DIR$/spec" isTestSource="true" />
|
10
|
+
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
|
11
|
+
</content>
|
12
|
+
<orderEntry type="jdk" jdkName="ruby-3.1.2-p20" jdkType="RUBY_SDK" />
|
13
|
+
<orderEntry type="sourceFolder" forTests="false" />
|
14
|
+
<orderEntry type="library" scope="PROVIDED" name="ast (v2.4.2, ruby-3.1.2-p20) [gem]" level="application" />
|
15
|
+
<orderEntry type="library" scope="PROVIDED" name="bundler (v2.3.18, ruby-3.1.2-p20) [gem]" level="application" />
|
16
|
+
<orderEntry type="library" scope="PROVIDED" name="json (v2.6.2, ruby-3.1.2-p20) [gem]" level="application" />
|
17
|
+
<orderEntry type="library" scope="PROVIDED" name="minitest (v5.16.3, ruby-3.1.2-p20) [gem]" level="application" />
|
18
|
+
<orderEntry type="library" scope="PROVIDED" name="parallel (v1.22.1, ruby-3.1.2-p20) [gem]" level="application" />
|
19
|
+
<orderEntry type="library" scope="PROVIDED" name="parser (v3.1.2.0, ruby-3.1.2-p20) [gem]" level="application" />
|
20
|
+
<orderEntry type="library" scope="PROVIDED" name="rainbow (v3.1.1, ruby-3.1.2-p20) [gem]" level="application" />
|
21
|
+
<orderEntry type="library" scope="PROVIDED" name="rake (v13.0.6, ruby-3.1.2-p20) [gem]" level="application" />
|
22
|
+
<orderEntry type="library" scope="PROVIDED" name="regexp_parser (v2.5.0, ruby-3.1.2-p20) [gem]" level="application" />
|
23
|
+
<orderEntry type="library" scope="PROVIDED" name="rexml (v3.2.5, ruby-3.1.2-p20) [gem]" level="application" />
|
24
|
+
<orderEntry type="library" scope="PROVIDED" name="rubocop (v1.33.0, ruby-3.1.2-p20) [gem]" level="application" />
|
25
|
+
<orderEntry type="library" scope="PROVIDED" name="rubocop-ast (v1.19.1, ruby-3.1.2-p20) [gem]" level="application" />
|
26
|
+
<orderEntry type="library" scope="PROVIDED" name="ruby-progressbar (v1.11.0, ruby-3.1.2-p20) [gem]" level="application" />
|
27
|
+
<orderEntry type="library" scope="PROVIDED" name="unicode-display_width (v2.2.0, ruby-3.1.2-p20) [gem]" level="application" />
|
28
|
+
</component>
|
29
|
+
<component name="RakeTasksCache">
|
30
|
+
<option name="myRootTask">
|
31
|
+
<RakeTaskImpl id="rake">
|
32
|
+
<subtasks>
|
33
|
+
<RakeTaskImpl description="Build cpf_cnpj_tools-0.1.0.gem into the pkg directory" fullCommand="build" id="build" />
|
34
|
+
<RakeTaskImpl id="build">
|
35
|
+
<subtasks>
|
36
|
+
<RakeTaskImpl description="Generate SHA512 checksum if cpf_cnpj_tools-0.1.0.gem into the checksums directory" fullCommand="build:checksum" id="checksum" />
|
37
|
+
</subtasks>
|
38
|
+
</RakeTaskImpl>
|
39
|
+
<RakeTaskImpl description="Remove any temporary products" fullCommand="clean" id="clean" />
|
40
|
+
<RakeTaskImpl description="Remove any generated files" fullCommand="clobber" id="clobber" />
|
41
|
+
<RakeTaskImpl description="Build and install cpf_cnpj_tools-0.1.0.gem into system gems" fullCommand="install" id="install" />
|
42
|
+
<RakeTaskImpl id="install">
|
43
|
+
<subtasks>
|
44
|
+
<RakeTaskImpl description="Build and install cpf_cnpj_tools-0.1.0.gem into system gems without network access" fullCommand="install:local" id="local" />
|
45
|
+
</subtasks>
|
46
|
+
</RakeTaskImpl>
|
47
|
+
<RakeTaskImpl description="Create tag v0.1.0 and build and push cpf_cnpj_tools-0.1.0.gem to rubygems.org" fullCommand="release[remote]" id="release[remote]" />
|
48
|
+
<RakeTaskImpl description="Run RuboCop" fullCommand="rubocop" id="rubocop" />
|
49
|
+
<RakeTaskImpl id="rubocop">
|
50
|
+
<subtasks>
|
51
|
+
<RakeTaskImpl description="Autocorrect RuboCop offenses (only when it's safe)" fullCommand="rubocop:autocorrect" id="autocorrect" />
|
52
|
+
<RakeTaskImpl description="Autocorrect RuboCop offenses (safe and unsafe)" fullCommand="rubocop:autocorrect_all" id="autocorrect_all" />
|
53
|
+
<RakeTaskImpl description="" fullCommand="rubocop:auto_correct" id="auto_correct" />
|
54
|
+
</subtasks>
|
55
|
+
</RakeTaskImpl>
|
56
|
+
<RakeTaskImpl description="Run tests" fullCommand="test" id="test" />
|
57
|
+
<RakeTaskImpl description="" fullCommand="default" id="default" />
|
58
|
+
<RakeTaskImpl description="" fullCommand="release" id="release" />
|
59
|
+
<RakeTaskImpl id="release">
|
60
|
+
<subtasks>
|
61
|
+
<RakeTaskImpl description="" fullCommand="release:guard_clean" id="guard_clean" />
|
62
|
+
<RakeTaskImpl description="" fullCommand="release:rubygem_push" id="rubygem_push" />
|
63
|
+
<RakeTaskImpl description="" fullCommand="release:source_control_push" id="source_control_push" />
|
64
|
+
</subtasks>
|
65
|
+
</RakeTaskImpl>
|
66
|
+
</subtasks>
|
67
|
+
</RakeTaskImpl>
|
68
|
+
</option>
|
69
|
+
</component>
|
70
|
+
</module>
|
data/.idea/modules.xml
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<project version="4">
|
3
|
+
<component name="ProjectModuleManager">
|
4
|
+
<modules>
|
5
|
+
<module fileurl="file://$PROJECT_DIR$/.idea/cpf_cnpj_tools.iml" filepath="$PROJECT_DIR$/.idea/cpf_cnpj_tools.iml" />
|
6
|
+
</modules>
|
7
|
+
</component>
|
8
|
+
</project>
|
data/.idea/vcs.xml
ADDED
data/.idea/workspace.xml
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<project version="4">
|
3
|
+
<component name="ChangeListManager">
|
4
|
+
<list default="true" id="ad094d7b-c701-4696-aa6d-20811d69a9f4" name="Changes" comment="">
|
5
|
+
<change beforePath="$PROJECT_DIR$/README.md" beforeDir="false" afterPath="$PROJECT_DIR$/README.md" afterDir="false" />
|
6
|
+
</list>
|
7
|
+
<option name="SHOW_DIALOG" value="false" />
|
8
|
+
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
9
|
+
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
10
|
+
<option name="LAST_RESOLUTION" value="IGNORE" />
|
11
|
+
</component>
|
12
|
+
<component name="Git.Settings">
|
13
|
+
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
14
|
+
</component>
|
15
|
+
<component name="MarkdownSettingsMigration">
|
16
|
+
<option name="stateVersion" value="1" />
|
17
|
+
</component>
|
18
|
+
<component name="ProjectId" id="2G0YdJp5P5d5f3HnUFKl61CT7ew" />
|
19
|
+
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
|
20
|
+
<component name="ProjectViewState">
|
21
|
+
<option name="hideEmptyMiddlePackages" value="true" />
|
22
|
+
<option name="showLibraryContents" value="true" />
|
23
|
+
</component>
|
24
|
+
<component name="PropertiesComponent"><![CDATA[{
|
25
|
+
"keyToString": {
|
26
|
+
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
27
|
+
"RunOnceActivity.ShowReadmeOnStart": "true",
|
28
|
+
"WebServerToolWindowFactoryState": "false",
|
29
|
+
"nodejs_package_manager_path": "npm",
|
30
|
+
"ruby.rails.projectView.checked": "true",
|
31
|
+
"settings.editor.selected.configurable": "Errors"
|
32
|
+
}
|
33
|
+
}]]></component>
|
34
|
+
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
|
35
|
+
<component name="SpringUtil" SPRING_PRE_LOADER_OPTION="true" RAKE_SPRING_PRE_LOADER_OPTION="true" RAILS_SPRING_PRE_LOADER_OPTION="true" />
|
36
|
+
<component name="TaskManager">
|
37
|
+
<task active="true" id="Default" summary="Default task">
|
38
|
+
<changelist id="ad094d7b-c701-4696-aa6d-20811d69a9f4" name="Changes" comment="" />
|
39
|
+
<created>1665527053664</created>
|
40
|
+
<option name="number" value="Default" />
|
41
|
+
<option name="presentableId" value="Default" />
|
42
|
+
<updated>1665527053664</updated>
|
43
|
+
<workItem from="1665527054889" duration="1995000" />
|
44
|
+
</task>
|
45
|
+
<servers />
|
46
|
+
</component>
|
47
|
+
<component name="TypeScriptGeneratedFilesManager">
|
48
|
+
<option name="version" value="3" />
|
49
|
+
</component>
|
50
|
+
<component name="Vcs.Log.Tabs.Properties">
|
51
|
+
<option name="TAB_STATES">
|
52
|
+
<map>
|
53
|
+
<entry key="MAIN">
|
54
|
+
<value>
|
55
|
+
<State />
|
56
|
+
</value>
|
57
|
+
</entry>
|
58
|
+
</map>
|
59
|
+
</option>
|
60
|
+
</component>
|
61
|
+
<component name="com.intellij.coverage.CoverageDataManagerImpl">
|
62
|
+
<SUITE FILE_PATH="coverage/cpf_cnpj_tools@test_invalid_cpf.rcov" NAME="test_invalid_cpf Coverage Results" MODIFIED="1665527793284" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="rcov" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" MODULE_NAME="cpf_cnpj_tools" />
|
63
|
+
<SUITE FILE_PATH="coverage/cpf_cnpj_tools@TestCpfCnpjTools.rcov" NAME="TestCpfCnpjTools Coverage Results" MODIFIED="1665528330730" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="rcov" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" MODULE_NAME="cpf_cnpj_tools" />
|
64
|
+
<SUITE FILE_PATH="coverage/cpf_cnpj_tools@test_invalid_cnpj.rcov" NAME="test_invalid_cnpj Coverage Results" MODIFIED="1665527916319" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="rcov" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" MODULE_NAME="cpf_cnpj_tools" />
|
65
|
+
<SUITE FILE_PATH="coverage/cpf_cnpj_tools@test_cnpj.rcov" NAME="test_cnpj Coverage Results" MODIFIED="1665527920522" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="rcov" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" MODULE_NAME="cpf_cnpj_tools" />
|
66
|
+
<SUITE FILE_PATH="coverage/cpf_cnpj_tools@test_cpf.rcov" NAME="test_cpf Coverage Results" MODIFIED="1665528568296" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="rcov" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" MODULE_NAME="cpf_cnpj_tools" />
|
67
|
+
<SUITE FILE_PATH="coverage/cpf_cnpj_tools@Testing.rcov" NAME="Testing Coverage Results" MODIFIED="1665528574697" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="rcov" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" MODULE_NAME="cpf_cnpj_tools" />
|
68
|
+
</component>
|
69
|
+
</project>
|
data/.rubocop.yml
ADDED
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
6
|
+
|
7
|
+
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
|
8
|
+
|
9
|
+
## Our Standards
|
10
|
+
|
11
|
+
Examples of behavior that contributes to a positive environment for our community include:
|
12
|
+
|
13
|
+
* Demonstrating empathy and kindness toward other people
|
14
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
15
|
+
* Giving and gracefully accepting constructive feedback
|
16
|
+
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
|
17
|
+
* Focusing on what is best not just for us as individuals, but for the overall community
|
18
|
+
|
19
|
+
Examples of unacceptable behavior include:
|
20
|
+
|
21
|
+
* The use of sexualized language or imagery, and sexual attention or
|
22
|
+
advances of any kind
|
23
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
24
|
+
* Public or private harassment
|
25
|
+
* Publishing others' private information, such as a physical or email
|
26
|
+
address, without their explicit permission
|
27
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
28
|
+
professional setting
|
29
|
+
|
30
|
+
## Enforcement Responsibilities
|
31
|
+
|
32
|
+
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
|
33
|
+
|
34
|
+
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
|
35
|
+
|
36
|
+
## Scope
|
37
|
+
|
38
|
+
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
|
39
|
+
|
40
|
+
## Enforcement
|
41
|
+
|
42
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at aria.diniz.dev@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
|
43
|
+
|
44
|
+
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
|
45
|
+
|
46
|
+
## Enforcement Guidelines
|
47
|
+
|
48
|
+
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
|
49
|
+
|
50
|
+
### 1. Correction
|
51
|
+
|
52
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
|
53
|
+
|
54
|
+
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
|
55
|
+
|
56
|
+
### 2. Warning
|
57
|
+
|
58
|
+
**Community Impact**: A violation through a single incident or series of actions.
|
59
|
+
|
60
|
+
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
|
61
|
+
|
62
|
+
### 3. Temporary Ban
|
63
|
+
|
64
|
+
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
|
65
|
+
|
66
|
+
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
|
67
|
+
|
68
|
+
### 4. Permanent Ban
|
69
|
+
|
70
|
+
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
|
71
|
+
|
72
|
+
**Consequence**: A permanent ban from any sort of public interaction within the community.
|
73
|
+
|
74
|
+
## Attribution
|
75
|
+
|
76
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
|
77
|
+
available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
78
|
+
|
79
|
+
Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
|
80
|
+
|
81
|
+
[homepage]: https://www.contributor-covenant.org
|
82
|
+
|
83
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
84
|
+
https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2022 Aria Diniz
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# CpfCnpjTools
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/cpf_cnpj_tools`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Install the gem and add to the application's Gemfile by executing:
|
10
|
+
|
11
|
+
$ bundle add cpf_cnpj_tools
|
12
|
+
|
13
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
14
|
+
|
15
|
+
$ gem install cpf_cnpj_tools
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
For usage, import the gem and create a new instance of it:
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
require "cpf_cnpj_tools"
|
23
|
+
|
24
|
+
generate = CpfCnpjTools::Generator.new
|
25
|
+
|
26
|
+
puts generate.generate_cpf # returns a valid CPF
|
27
|
+
puts generate.generate_cnpj # returns a valid cnpj
|
28
|
+
puts generate.validate_cpf("999999900") # validate returning true or false
|
29
|
+
puts generate.validate_cnpj("99999999000100") # validate returning true or false
|
30
|
+
```
|
31
|
+
|
32
|
+
## Contributing
|
33
|
+
|
34
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/ariasdiniz/cpf_cnpj_tools. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/ariasdiniz/cpf_cnpj_tools/blob/main/CODE_OF_CONDUCT.md).
|
35
|
+
|
36
|
+
## License
|
37
|
+
|
38
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
39
|
+
|
40
|
+
## Code of Conduct
|
41
|
+
|
42
|
+
Everyone interacting in the CpfCnpjTools project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/ariasdiniz/cpf_cnpj_tools/blob/main/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
require "rake/testtask"
|
5
|
+
|
6
|
+
Rake::TestTask.new(:test) do |t|
|
7
|
+
t.libs << "test"
|
8
|
+
t.libs << "lib"
|
9
|
+
t.test_files = FileList["test/**/test_*.rb"]
|
10
|
+
end
|
11
|
+
|
12
|
+
require "rubocop/rake_task"
|
13
|
+
|
14
|
+
RuboCop::RakeTask.new
|
15
|
+
|
16
|
+
task default: %i[test rubocop]
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/cpf_cnpj_tools/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "cpf_cnpj_tools"
|
7
|
+
spec.version = CpfCnpjTools::VERSION
|
8
|
+
spec.authors = ["Aria Diniz"]
|
9
|
+
spec.email = ["aria.diniz.dev@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = "A tool for generating and validating CPF/CNPJ numbers"
|
12
|
+
spec.description = "With this tool you will be able to generate and validate brazilian CPF and CNPJ numbers."
|
13
|
+
spec.homepage = "https://github.com/ariasdiniz/cpf_cnpj_tools"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.required_ruby_version = ">= 2.6"
|
16
|
+
|
17
|
+
spec.metadata["documentation_uri"] = "https://rubydoc.info/gems/cpf_cnpj_tools"
|
18
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
19
|
+
spec.metadata["source_code_uri"] = "https://github.com/ariasdiniz/cpf_cnpj_tools"
|
20
|
+
|
21
|
+
# Specify which files should be added to the gem when it is released.
|
22
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
23
|
+
spec.files = Dir.chdir(__dir__) do
|
24
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
25
|
+
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
|
26
|
+
end
|
27
|
+
end
|
28
|
+
spec.bindir = "exe"
|
29
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ["lib"]
|
31
|
+
|
32
|
+
# Uncomment to register a new dependency of your gem
|
33
|
+
# spec.add_dependency "example-gem", "~> 1.0"
|
34
|
+
|
35
|
+
# For more information and examples about making a new gem, check out our
|
36
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
37
|
+
end
|
@@ -0,0 +1,123 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "cpf_cnpj_tools/version"
|
4
|
+
|
5
|
+
module CpfCnpjTools
|
6
|
+
##
|
7
|
+
# Class responsible for generating and
|
8
|
+
# validating CPF and CNPJ numbers
|
9
|
+
class Generator
|
10
|
+
CPF1DIGIT = [10, 9, 8, 7, 6, 5, 4, 3, 2].freeze
|
11
|
+
CPF2DIGIT = [11, 10, 9, 8, 7, 6, 5, 4, 3, 2].freeze
|
12
|
+
CNPJ1DIGIT = [5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2].freeze
|
13
|
+
CNPJ2DIGIT = [6, 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2].freeze
|
14
|
+
|
15
|
+
##
|
16
|
+
# Method for generating valid CPF numbers
|
17
|
+
# @return String
|
18
|
+
def generate_cpf
|
19
|
+
base = generate_base
|
20
|
+
base << generate_identifier(base, true)
|
21
|
+
base << generate_identifier(base, false)
|
22
|
+
base.join
|
23
|
+
end
|
24
|
+
|
25
|
+
##
|
26
|
+
# Method for generating valid CNPJ numbers
|
27
|
+
# @return String
|
28
|
+
def generate_cnpj
|
29
|
+
base = generate_base(cnpj: true)
|
30
|
+
base << generate_identifier(base, true, cpf: false)
|
31
|
+
base << generate_identifier(base, false, cpf: false)
|
32
|
+
base.join
|
33
|
+
end
|
34
|
+
|
35
|
+
##
|
36
|
+
# Method for validating CPF numbers.
|
37
|
+
# @param cpf (String, Integer)
|
38
|
+
# @return Boolean
|
39
|
+
def validate_cpf(cpf)
|
40
|
+
cpf_array = cpf.to_s.split('').map!(&:to_i)
|
41
|
+
first_digit = cpf_array[-2]
|
42
|
+
second_digit = cpf_array[-1]
|
43
|
+
base_cpf = cpf_array[0..8]
|
44
|
+
calculated_first_digit = generate_identifier(base_cpf, true)
|
45
|
+
calculated_second_digit = generate_identifier(base_cpf << calculated_first_digit, false)
|
46
|
+
return false if (first_digit != calculated_first_digit) || (second_digit != calculated_second_digit)
|
47
|
+
|
48
|
+
true
|
49
|
+
end
|
50
|
+
|
51
|
+
##
|
52
|
+
# Method for validating CNPJ numbers.
|
53
|
+
# @param cnpj (String, Integer)
|
54
|
+
# @return Boolean
|
55
|
+
def validate_cnpj(cnpj)
|
56
|
+
cnpj_array = cnpj.to_s.split('').map!(&:to_i)
|
57
|
+
first_digit = cnpj_array[-2]
|
58
|
+
second_digit = cnpj_array[-1]
|
59
|
+
base_cnpj = cnpj_array[0..11]
|
60
|
+
calculated_first_digit = generate_identifier(base_cnpj, true, cpf: false)
|
61
|
+
calculated_second_digit = generate_identifier(base_cnpj << calculated_first_digit, false, cpf: false)
|
62
|
+
return false if (first_digit != calculated_first_digit) || (second_digit != calculated_second_digit)
|
63
|
+
|
64
|
+
true
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
##
|
70
|
+
# Generate the first numbers of CPF/CNPJ
|
71
|
+
# randomly.
|
72
|
+
# @param cnpj (Boolean)
|
73
|
+
# @return (Array)
|
74
|
+
def generate_base(cnpj: false)
|
75
|
+
base_number = []
|
76
|
+
9.times do
|
77
|
+
base_number << rand(10)
|
78
|
+
end
|
79
|
+
if cnpj
|
80
|
+
base_number.delete_at(-1)
|
81
|
+
base_number.push 0, 0, 0, 1
|
82
|
+
end
|
83
|
+
base_number
|
84
|
+
end
|
85
|
+
|
86
|
+
##
|
87
|
+
# Generate the first and second identifier numbers
|
88
|
+
# of the CPF/CNPJ.
|
89
|
+
# @param first_numbers (Array)
|
90
|
+
# @param first (Boolean)
|
91
|
+
# @param cpf (Boolean)
|
92
|
+
# @return Integer
|
93
|
+
def generate_identifier(first_numbers, first, cpf: true)
|
94
|
+
multipliers = if cpf
|
95
|
+
first ? CPF1DIGIT : CPF2DIGIT
|
96
|
+
else
|
97
|
+
first ? CNPJ1DIGIT : CNPJ2DIGIT
|
98
|
+
end
|
99
|
+
product = []
|
100
|
+
first_numbers.length.times do |index|
|
101
|
+
product << first_numbers[index] * multipliers[index]
|
102
|
+
end
|
103
|
+
generate_valid_digit(product)
|
104
|
+
end
|
105
|
+
|
106
|
+
##
|
107
|
+
# Calculates the value of a valid identifier digit.
|
108
|
+
# @param digits (Array)
|
109
|
+
# @return Integer
|
110
|
+
def generate_valid_digit(digits)
|
111
|
+
sum = 0
|
112
|
+
digits.each do |item|
|
113
|
+
sum += item
|
114
|
+
end
|
115
|
+
remainder = sum % 11
|
116
|
+
if remainder < 2
|
117
|
+
0
|
118
|
+
else
|
119
|
+
11 - remainder
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
metadata
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cpf_cnpj_tools
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Aria Diniz
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-10-11 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: With this tool you will be able to generate and validate brazilian CPF
|
14
|
+
and CNPJ numbers.
|
15
|
+
email:
|
16
|
+
- aria.diniz.dev@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- ".idea/cpf_cnpj_tools.iml"
|
22
|
+
- ".idea/modules.xml"
|
23
|
+
- ".idea/vcs.xml"
|
24
|
+
- ".idea/workspace.xml"
|
25
|
+
- ".rubocop.yml"
|
26
|
+
- CHANGELOG.md
|
27
|
+
- CODE_OF_CONDUCT.md
|
28
|
+
- Gemfile
|
29
|
+
- LICENSE.txt
|
30
|
+
- README.md
|
31
|
+
- Rakefile
|
32
|
+
- cpf_cnpj_tools.gemspec
|
33
|
+
- lib/cpf_cnpj_tools.rb
|
34
|
+
- lib/cpf_cnpj_tools/version.rb
|
35
|
+
- sig/cpf_cnpj_tools.rbs
|
36
|
+
homepage: https://github.com/ariasdiniz/cpf_cnpj_tools
|
37
|
+
licenses:
|
38
|
+
- MIT
|
39
|
+
metadata:
|
40
|
+
documentation_uri: https://rubydoc.info/gems/cpf_cnpj_tools
|
41
|
+
homepage_uri: https://github.com/ariasdiniz/cpf_cnpj_tools
|
42
|
+
source_code_uri: https://github.com/ariasdiniz/cpf_cnpj_tools
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options: []
|
45
|
+
require_paths:
|
46
|
+
- lib
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '2.6'
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
requirements: []
|
58
|
+
rubygems_version: 3.3.7
|
59
|
+
signing_key:
|
60
|
+
specification_version: 4
|
61
|
+
summary: A tool for generating and validating CPF/CNPJ numbers
|
62
|
+
test_files: []
|