br-utils 0.1.0
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 +7 -0
- data/.gitignore +120 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +21 -0
- data/README.md +348 -0
- data/Rakefile +6 -0
- data/examples/boleto_usage_example.rb +79 -0
- data/examples/cep_usage_example.rb +148 -0
- data/examples/cnh_usage_example.rb +120 -0
- data/examples/cnpj_usage_example.rb +227 -0
- data/examples/cpf_usage_example.rb +237 -0
- data/examples/currency_usage_example.rb +266 -0
- data/examples/date_usage_example.rb +259 -0
- data/examples/email_usage_example.rb +321 -0
- data/examples/legal_nature_usage_example.rb +437 -0
- data/examples/legal_process_usage_example.rb +444 -0
- data/examples/license_plate_usage_example.rb +440 -0
- data/examples/phone_usage_example.rb +595 -0
- data/examples/pis_usage_example.rb +588 -0
- data/examples/renavam_usage_example.rb +499 -0
- data/examples/voter_id_usage_example.rb +573 -0
- data/lib/brazilian-utils/boleto-utils.rb +176 -0
- data/lib/brazilian-utils/cep-utils.rb +330 -0
- data/lib/brazilian-utils/cnh-utils.rb +88 -0
- data/lib/brazilian-utils/cnpj-utils.rb +202 -0
- data/lib/brazilian-utils/cpf-utils.rb +192 -0
- data/lib/brazilian-utils/currency-utils.rb +226 -0
- data/lib/brazilian-utils/data/legal_process_ids.json +38 -0
- data/lib/brazilian-utils/date-utils.rb +244 -0
- data/lib/brazilian-utils/email-utils.rb +54 -0
- data/lib/brazilian-utils/legal-nature-utils.rb +235 -0
- data/lib/brazilian-utils/legal-process-utils.rb +240 -0
- data/lib/brazilian-utils/license-plate-utils.rb +279 -0
- data/lib/brazilian-utils/phone-utils.rb +272 -0
- data/lib/brazilian-utils/pis-utils.rb +151 -0
- data/lib/brazilian-utils/renavam-utils.rb +113 -0
- data/lib/brazilian-utils/voter-id-utils.rb +165 -0
- metadata +123 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 23f897e35167135baa4eeb00f625bdd6f69656b86ce6ca62229f2dcd4a718f94
|
|
4
|
+
data.tar.gz: 1737c2f0bc7a3799ee6a3c87d8bf065a27b992eefe4fe4907be0c0f92536bc5e
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: d8e78d62b1b1c5173d2eed7088c55dfe3e7934d3faf0d6f527e654242228900fcebb29ac6fe84d5023a779292453d57a22f1ba954aa979c768b515ba5ac94c4e
|
|
7
|
+
data.tar.gz: 6978c693525a310ec21fac4a00c76128fe374bc0aed83c5a897f2a62dabc57578be80dafee3be11cab72bcd106749cc966d53518caa26477568c229ebcdde994
|
data/.gitignore
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/.bundle/
|
|
2
|
+
/.yardoc
|
|
3
|
+
/Gemfile.lock
|
|
4
|
+
/_yardoc/
|
|
5
|
+
/coverage/
|
|
6
|
+
/doc/
|
|
7
|
+
/pkg/
|
|
8
|
+
/spec/reports/
|
|
9
|
+
/tmp/
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
# Created by https://www.gitignore.io/api/ruby,rubymine
|
|
13
|
+
|
|
14
|
+
### Ruby ###
|
|
15
|
+
*.gem
|
|
16
|
+
*.rbc
|
|
17
|
+
/.config
|
|
18
|
+
/coverage/
|
|
19
|
+
/InstalledFiles
|
|
20
|
+
/pkg/
|
|
21
|
+
/spec/reports/
|
|
22
|
+
/spec/examples.txt
|
|
23
|
+
/test/tmp/
|
|
24
|
+
/test/version_tmp/
|
|
25
|
+
/tmp/
|
|
26
|
+
|
|
27
|
+
# Used by dotenv library to load environment variables.
|
|
28
|
+
# .env
|
|
29
|
+
|
|
30
|
+
## Specific to RubyMotion:
|
|
31
|
+
.dat*
|
|
32
|
+
.repl_history
|
|
33
|
+
build/
|
|
34
|
+
*.bridgesupport
|
|
35
|
+
build-iPhoneOS/
|
|
36
|
+
build-iPhoneSimulator/
|
|
37
|
+
|
|
38
|
+
## Specific to RubyMotion (use of CocoaPods):
|
|
39
|
+
#
|
|
40
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
|
41
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
|
42
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
|
43
|
+
#
|
|
44
|
+
# vendor/Pods/
|
|
45
|
+
|
|
46
|
+
## Documentation cache and generated files:
|
|
47
|
+
/.yardoc/
|
|
48
|
+
/_yardoc/
|
|
49
|
+
/doc/
|
|
50
|
+
/rdoc/
|
|
51
|
+
|
|
52
|
+
## Environment normalization:
|
|
53
|
+
/.bundle/
|
|
54
|
+
/vendor/bundle
|
|
55
|
+
/lib/bundler/man/
|
|
56
|
+
|
|
57
|
+
# for a library or gem, you might want to ignore these files since the code is
|
|
58
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
59
|
+
# Gemfile.lock
|
|
60
|
+
# .ruby-version
|
|
61
|
+
# .ruby-gemset
|
|
62
|
+
|
|
63
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
|
64
|
+
.rvmrc
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
### RubyMine ###
|
|
68
|
+
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
|
|
69
|
+
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
|
70
|
+
|
|
71
|
+
# User-specific stuff:
|
|
72
|
+
.idea/workspace.xml
|
|
73
|
+
.idea/tasks.xml
|
|
74
|
+
.idea/dictionaries
|
|
75
|
+
.idea/vcs.xml
|
|
76
|
+
.idea/jsLibraryMappings.xml
|
|
77
|
+
*.idea
|
|
78
|
+
|
|
79
|
+
# Sensitive or high-churn files:
|
|
80
|
+
.idea/dataSources.ids
|
|
81
|
+
.idea/dataSources.xml
|
|
82
|
+
.idea/dataSources.local.xml
|
|
83
|
+
.idea/sqlDataSources.xml
|
|
84
|
+
.idea/dynamic.xml
|
|
85
|
+
.idea/uiDesigner.xml
|
|
86
|
+
|
|
87
|
+
# Gradle:
|
|
88
|
+
.idea/gradle.xml
|
|
89
|
+
.idea/libraries
|
|
90
|
+
|
|
91
|
+
# Mongo Explorer plugin:
|
|
92
|
+
.idea/mongoSettings.xml
|
|
93
|
+
|
|
94
|
+
## File-based project format:
|
|
95
|
+
*.iws
|
|
96
|
+
|
|
97
|
+
## Plugin-specific files:
|
|
98
|
+
|
|
99
|
+
# IntelliJ
|
|
100
|
+
/out/
|
|
101
|
+
|
|
102
|
+
# mpeltonen/sbt-idea plugin
|
|
103
|
+
.idea_modules/
|
|
104
|
+
|
|
105
|
+
# JIRA plugin
|
|
106
|
+
atlassian-ide-plugin.xml
|
|
107
|
+
|
|
108
|
+
# Crashlytics plugin (for Android Studio and IntelliJ)
|
|
109
|
+
com_crashlytics_export_strings.xml
|
|
110
|
+
crashlytics.properties
|
|
111
|
+
crashlytics-build.properties
|
|
112
|
+
fabric.properties
|
|
113
|
+
|
|
114
|
+
### RubyMine Patch ###
|
|
115
|
+
# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721
|
|
116
|
+
|
|
117
|
+
# *.iml
|
|
118
|
+
# modules.xml
|
|
119
|
+
# .idea/misc.xml
|
|
120
|
+
# *.ipr
|
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2016 Alex Rocha
|
|
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,348 @@
|
|
|
1
|
+
# :brazil: Brazilian Utils
|
|
2
|
+
|
|
3
|
+
> Biblioteca de utilitários para dados específicos do Brasil / Utils library for Brazilian-specific data
|
|
4
|
+
|
|
5
|
+
[](https://badge.fury.io/rb/br-utils)
|
|
6
|
+

|
|
7
|
+
|
|
8
|
+
[🇧🇷 Português](#português) | [🇺🇸 English](#english)
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## Português
|
|
13
|
+
|
|
14
|
+
### 📋 Recursos
|
|
15
|
+
|
|
16
|
+
Utilitários para trabalhar com formatos de dados brasileiros:
|
|
17
|
+
|
|
18
|
+
- **CPF** - Validação, formatação e geração
|
|
19
|
+
- **CNH** - Validação de Carteira Nacional de Habilitação
|
|
20
|
+
- **CNPJ** - Validação, formatação e geração
|
|
21
|
+
- **CEP** - Validação, formatação e busca via API ViaCEP
|
|
22
|
+
- **Moeda** - Formatação de Real (R$) e conversão para extenso
|
|
23
|
+
- **Data** - Verificação de feriados e conversão para texto
|
|
24
|
+
- **Email** - Validação (RFC 5322)
|
|
25
|
+
- **Natureza Jurídica** - Validação de códigos oficiais
|
|
26
|
+
- **Processos Judiciais** - Validação, formatação e geração
|
|
27
|
+
- **Placas de Veículos** - Validação e conversão (antigo/Mercosul)
|
|
28
|
+
- **Telefone** - Validação e formatação (móvel/fixo)
|
|
29
|
+
- **PIS** - Validação, formatação e geração (PIS/PASEP)
|
|
30
|
+
- **RENAVAM** - Validação de registro de veículos
|
|
31
|
+
- **Título de Eleitor** - Validação, formatação e geração
|
|
32
|
+
|
|
33
|
+
### 💾 Instalação
|
|
34
|
+
|
|
35
|
+
```ruby
|
|
36
|
+
gem 'br-utils'
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
bundle install
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### 🚀 Uso Rápido
|
|
44
|
+
|
|
45
|
+
```ruby
|
|
46
|
+
# CPF
|
|
47
|
+
require 'brazilian-utils/cpf-utils'
|
|
48
|
+
BrazilianUtils::CPFUtils.is_valid('11144477735') # => true
|
|
49
|
+
BrazilianUtils::CPFUtils.format_cpf('11144477735') # => "111.444.777-35"
|
|
50
|
+
BrazilianUtils::CPFUtils.generate # => "12345678901"
|
|
51
|
+
|
|
52
|
+
# CNPJ
|
|
53
|
+
require 'brazilian-utils/cnpj-utils'
|
|
54
|
+
BrazilianUtils::CNPJUtils.is_valid('34665388000161') # => true
|
|
55
|
+
BrazilianUtils::CNPJUtils.format_cnpj('34665388000161') # => "34.665.388/0001-61"
|
|
56
|
+
|
|
57
|
+
# CEP
|
|
58
|
+
require 'brazilian-utils/cep-utils'
|
|
59
|
+
BrazilianUtils::CEPUtils.format_cep('01310100') # => "01310-100"
|
|
60
|
+
BrazilianUtils::CEPUtils.get_address('01310100') # => {...endereço completo...}
|
|
61
|
+
|
|
62
|
+
# Telefone
|
|
63
|
+
require 'brazilian-utils/phone-utils'
|
|
64
|
+
BrazilianUtils::PhoneUtils.is_valid('11987654321') # => true
|
|
65
|
+
BrazilianUtils::PhoneUtils.format('11987654321') # => "(11)98765-4321"
|
|
66
|
+
|
|
67
|
+
# Placa de Veículo
|
|
68
|
+
require 'brazilian-utils/license-plate-utils'
|
|
69
|
+
BrazilianUtils::LicensePlateUtils.is_valid('ABC1234') # => true
|
|
70
|
+
BrazilianUtils::LicensePlateUtils.convert_to_mercosul('ABC1234') # => "ABC1C34"
|
|
71
|
+
|
|
72
|
+
# Título de Eleitor
|
|
73
|
+
require 'brazilian-utils/voter-id-utils'
|
|
74
|
+
BrazilianUtils::VoterIdUtils.is_valid_voter_id('690847092828') # => true
|
|
75
|
+
BrazilianUtils::VoterIdUtils.format('690847092828') # => "6908 4709 28 28"
|
|
76
|
+
BrazilianUtils::VoterIdUtils.generate('SP') # => "123456780140"
|
|
77
|
+
|
|
78
|
+
# Moeda
|
|
79
|
+
require 'brazilian-utils/currency-utils'
|
|
80
|
+
BrazilianUtils::CurrencyUtils.format_currency(1234.56) # => "R$ 1.234,56"
|
|
81
|
+
BrazilianUtils::CurrencyUtils.number_to_text(1234.56) # => "mil duzentos e trinta e quatro reais..."
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### 📚 Documentação Detalhada
|
|
85
|
+
|
|
86
|
+
Para exemplos completos de cada utilitário, consulte a pasta [`examples/`](examples/).
|
|
87
|
+
|
|
88
|
+
**Principais Módulos:**
|
|
89
|
+
- [`CPFUtils`](lib/brazilian-utils/cpf-utils.rb) - Validação e formatação de CPF
|
|
90
|
+
- [`CNPJUtils`](lib/brazilian-utils/cnpj-utils.rb) - Validação e formatação de CNPJ
|
|
91
|
+
- [`CEPUtils`](lib/brazilian-utils/cep-utils.rb) - Validação de CEP e busca de endereços
|
|
92
|
+
- [`PhoneUtils`](lib/brazilian-utils/phone-utils.rb) - Validação de telefones
|
|
93
|
+
- [`LicensePlateUtils`](lib/brazilian-utils/license-plate-utils.rb) - Placas de veículos
|
|
94
|
+
- [`VoterIdUtils`](lib/brazilian-utils/voter-id-utils.rb) - Títulos de eleitor
|
|
95
|
+
- [`CurrencyUtils`](lib/brazilian-utils/currency-utils.rb) - Formatação de moeda
|
|
96
|
+
- [`DateUtils`](lib/brazilian-utils/date-utils.rb) - Feriados e datas por extenso
|
|
97
|
+
- [`EmailUtils`](lib/brazilian-utils/email-utils.rb) - Validação de email
|
|
98
|
+
- [`LegalNatureUtils`](lib/brazilian-utils/legal-nature-utils.rb) - Natureza jurídica
|
|
99
|
+
- [`LegalProcessUtils`](lib/brazilian-utils/legal-process-utils.rb) - Processos judiciais
|
|
100
|
+
- [`PISUtils`](lib/brazilian-utils/pis-utils.rb) - PIS/PASEP
|
|
101
|
+
- [`RENAVAMUtils`](lib/brazilian-utils/renavam-utils.rb) - RENAVAM
|
|
102
|
+
- [`CNHUtils`](lib/brazilian-utils/cnh-utils.rb) - CNH
|
|
103
|
+
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
## English
|
|
107
|
+
|
|
108
|
+
### 📋 Features
|
|
109
|
+
|
|
110
|
+
Utilities for working with Brazilian data formats:
|
|
111
|
+
|
|
112
|
+
- **CPF** - Validation, formatting, and generation
|
|
113
|
+
- **CNH** - Driver's license validation
|
|
114
|
+
- **CNPJ** - Company tax ID validation, formatting, and generation
|
|
115
|
+
- **CEP** - Postal code validation, formatting, and address lookup (ViaCEP API)
|
|
116
|
+
- **Currency** - Brazilian Real (R$) formatting and text conversion
|
|
117
|
+
- **Date** - Holiday checking and date-to-text conversion
|
|
118
|
+
- **Email** - Email validation (RFC 5322)
|
|
119
|
+
- **Legal Nature** - Official business entity code validation
|
|
120
|
+
- **Legal Process** - Judicial process ID validation, formatting, and generation
|
|
121
|
+
- **License Plate** - Vehicle plate validation and format conversion (old/Mercosul)
|
|
122
|
+
- **Phone** - Mobile and landline validation and formatting
|
|
123
|
+
- **PIS** - Social security number validation, formatting, and generation
|
|
124
|
+
- **RENAVAM** - Vehicle registration validation
|
|
125
|
+
- **Voter ID** - Voter registration validation, formatting, and generation
|
|
126
|
+
|
|
127
|
+
### 💾 Installation
|
|
128
|
+
|
|
129
|
+
```ruby
|
|
130
|
+
gem 'br-utils'
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
```bash
|
|
134
|
+
bundle install
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### 🚀 Quick Start
|
|
138
|
+
|
|
139
|
+
```ruby
|
|
140
|
+
# CPF
|
|
141
|
+
require 'brazilian-utils/cpf-utils'
|
|
142
|
+
BrazilianUtils::CPFUtils.is_valid('11144477735') # => true
|
|
143
|
+
BrazilianUtils::CPFUtils.format_cpf('11144477735') # => "111.444.777-35"
|
|
144
|
+
BrazilianUtils::CPFUtils.generate # => "12345678901"
|
|
145
|
+
|
|
146
|
+
# CNPJ
|
|
147
|
+
require 'brazilian-utils/cnpj-utils'
|
|
148
|
+
BrazilianUtils::CNPJUtils.is_valid('34665388000161') # => true
|
|
149
|
+
BrazilianUtils::CNPJUtils.format_cnpj('34665388000161') # => "34.665.388/0001-61"
|
|
150
|
+
|
|
151
|
+
# CEP (Postal Code)
|
|
152
|
+
require 'brazilian-utils/cep-utils'
|
|
153
|
+
BrazilianUtils::CEPUtils.format_cep('01310100') # => "01310-100"
|
|
154
|
+
BrazilianUtils::CEPUtils.get_address('01310100') # => {...complete address...}
|
|
155
|
+
|
|
156
|
+
# Phone
|
|
157
|
+
require 'brazilian-utils/phone-utils'
|
|
158
|
+
BrazilianUtils::PhoneUtils.is_valid('11987654321') # => true
|
|
159
|
+
BrazilianUtils::PhoneUtils.format('11987654321') # => "(11)98765-4321"
|
|
160
|
+
|
|
161
|
+
# License Plate
|
|
162
|
+
require 'brazilian-utils/license-plate-utils'
|
|
163
|
+
BrazilianUtils::LicensePlateUtils.is_valid('ABC1234') # => true
|
|
164
|
+
BrazilianUtils::LicensePlateUtils.convert_to_mercosul('ABC1234') # => "ABC1C34"
|
|
165
|
+
|
|
166
|
+
# Voter ID
|
|
167
|
+
require 'brazilian-utils/voter-id-utils'
|
|
168
|
+
BrazilianUtils::VoterIdUtils.is_valid_voter_id('690847092828') # => true
|
|
169
|
+
BrazilianUtils::VoterIdUtils.format('690847092828') # => "6908 4709 28 28"
|
|
170
|
+
BrazilianUtils::VoterIdUtils.generate('SP') # => "123456780140"
|
|
171
|
+
|
|
172
|
+
# Currency
|
|
173
|
+
require 'brazilian-utils/currency-utils'
|
|
174
|
+
BrazilianUtils::CurrencyUtils.format_currency(1234.56) # => "R$ 1.234,56"
|
|
175
|
+
BrazilianUtils::CurrencyUtils.number_to_text(1234.56) # => "mil duzentos e trinta e quatro reais..."
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### 📚 Full Documentation
|
|
179
|
+
|
|
180
|
+
For detailed examples of each utility, check the [`examples/`](examples/) folder.
|
|
181
|
+
|
|
182
|
+
**Main Modules:**
|
|
183
|
+
- [`CPFUtils`](lib/brazilian-utils/cpf-utils.rb) - CPF validation and formatting
|
|
184
|
+
- [`CNPJUtils`](lib/brazilian-utils/cnpj-utils.rb) - CNPJ validation and formatting
|
|
185
|
+
- [`CEPUtils`](lib/brazilian-utils/cep-utils.rb) - CEP validation and address lookup
|
|
186
|
+
- [`PhoneUtils`](lib/brazilian-utils/phone-utils.rb) - Phone validation
|
|
187
|
+
- [`LicensePlateUtils`](lib/brazilian-utils/license-plate-utils.rb) - Vehicle plates
|
|
188
|
+
- [`VoterIdUtils`](lib/brazilian-utils/voter-id-utils.rb) - Voter IDs
|
|
189
|
+
- [`CurrencyUtils`](lib/brazilian-utils/currency-utils.rb) - Currency formatting
|
|
190
|
+
- [`DateUtils`](lib/brazilian-utils/date-utils.rb) - Holidays and date text
|
|
191
|
+
- [`EmailUtils`](lib/brazilian-utils/email-utils.rb) - Email validation
|
|
192
|
+
- [`LegalNatureUtils`](lib/brazilian-utils/legal-nature-utils.rb) - Legal nature codes
|
|
193
|
+
- [`LegalProcessUtils`](lib/brazilian-utils/legal-process-utils.rb) - Legal process IDs
|
|
194
|
+
- [`PISUtils`](lib/brazilian-utils/pis-utils.rb) - PIS/PASEP
|
|
195
|
+
- [`RENAVAMUtils`](lib/brazilian-utils/renavam-utils.rb) - Vehicle registration
|
|
196
|
+
- [`CNHUtils`](lib/brazilian-utils/cnh-utils.rb) - Driver's license
|
|
197
|
+
|
|
198
|
+
---
|
|
199
|
+
|
|
200
|
+
## 🧪 Development
|
|
201
|
+
|
|
202
|
+
```bash
|
|
203
|
+
# Install dependencies
|
|
204
|
+
bundle install
|
|
205
|
+
|
|
206
|
+
# Run tests
|
|
207
|
+
bundle exec rspec
|
|
208
|
+
|
|
209
|
+
# Run specific test
|
|
210
|
+
bundle exec rspec spec/cpf_utils_spec.rb
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
## 📖 API Reference
|
|
214
|
+
|
|
215
|
+
### Common Patterns
|
|
216
|
+
|
|
217
|
+
Most utilities follow these patterns:
|
|
218
|
+
|
|
219
|
+
**Validation:**
|
|
220
|
+
```ruby
|
|
221
|
+
.is_valid(value) # Main validation method
|
|
222
|
+
.valid?(value) # Alias for is_valid
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
**Formatting:**
|
|
226
|
+
```ruby
|
|
227
|
+
.format(value) # Format with standard symbols
|
|
228
|
+
.remove_symbols(value) # Remove formatting symbols
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
**Generation:**
|
|
232
|
+
```ruby
|
|
233
|
+
.generate # Generate random valid value
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
### Utility-Specific Methods
|
|
237
|
+
|
|
238
|
+
**CEP:**
|
|
239
|
+
- `get_address(cep)` - Fetch address from CEP
|
|
240
|
+
- `get_cep_information_from_address(uf, city, street)` - Find CEPs
|
|
241
|
+
|
|
242
|
+
**Phone:**
|
|
243
|
+
- `is_valid(phone, type:)` - Validate with type (:mobile or :landline)
|
|
244
|
+
- `remove_international_dialing_code(phone)` - Remove +55/55
|
|
245
|
+
|
|
246
|
+
**License Plate:**
|
|
247
|
+
- `convert_to_mercosul(plate)` - Convert old format to Mercosul
|
|
248
|
+
- `get_format(plate)` - Detect format ("LLLNNNN" or "LLLNLNN")
|
|
249
|
+
|
|
250
|
+
**Voter ID:**
|
|
251
|
+
- `generate(uf)` - Generate for specific state
|
|
252
|
+
|
|
253
|
+
**Currency:**
|
|
254
|
+
- `format_currency(value)` - Format as R$ X.XXX,XX
|
|
255
|
+
- `number_to_text(value)` - Convert to Brazilian Portuguese text
|
|
256
|
+
|
|
257
|
+
**Date:**
|
|
258
|
+
- `is_holiday(date, uf)` - Check if date is holiday
|
|
259
|
+
- `convert_date_to_text(date)` - Convert to Portuguese text
|
|
260
|
+
|
|
261
|
+
**Legal Nature:**
|
|
262
|
+
- `get_description(code)` - Get description for code
|
|
263
|
+
- `list_by_category(category)` - List codes by category (1-5)
|
|
264
|
+
|
|
265
|
+
**Legal Process:**
|
|
266
|
+
- `generate(year, orgao)` - Generate for specific year and judicial segment
|
|
267
|
+
|
|
268
|
+
## 📊 Examples by Use Case
|
|
269
|
+
|
|
270
|
+
### Form Validation
|
|
271
|
+
|
|
272
|
+
```ruby
|
|
273
|
+
# Validate user input
|
|
274
|
+
cpf = params[:cpf]
|
|
275
|
+
if BrazilianUtils::CPFUtils.valid?(cpf)
|
|
276
|
+
# Process valid CPF
|
|
277
|
+
else
|
|
278
|
+
errors.add(:cpf, "inválido")
|
|
279
|
+
end
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
### Display Formatting
|
|
283
|
+
|
|
284
|
+
```ruby
|
|
285
|
+
# Format for display
|
|
286
|
+
cpf = "11144477735"
|
|
287
|
+
formatted = BrazilianUtils::CPFUtils.format_cpf(cpf)
|
|
288
|
+
puts formatted # => "111.444.777-35"
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
### Test Data Generation
|
|
292
|
+
|
|
293
|
+
```ruby
|
|
294
|
+
# Generate test data
|
|
295
|
+
10.times do
|
|
296
|
+
cpf = BrazilianUtils::CPFUtils.generate
|
|
297
|
+
puts BrazilianUtils::CPFUtils.format_cpf(cpf)
|
|
298
|
+
end
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
### API Integration
|
|
302
|
+
|
|
303
|
+
```ruby
|
|
304
|
+
# Lookup address from CEP
|
|
305
|
+
address = BrazilianUtils::CEPUtils.get_address('01310100')
|
|
306
|
+
if address
|
|
307
|
+
puts "#{address.logradouro}, #{address.bairro}"
|
|
308
|
+
puts "#{address.localidade} - #{address.uf}"
|
|
309
|
+
end
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
---
|
|
313
|
+
|
|
314
|
+
## 🤝 Contributing
|
|
315
|
+
|
|
316
|
+
Contributions are welcome! Please feel free to submit pull requests.
|
|
317
|
+
|
|
318
|
+
**Como contribuir / How to contribute:**
|
|
319
|
+
|
|
320
|
+
1. Fork o projeto / Fork the project
|
|
321
|
+
2. Crie seu branch (`git checkout -b feature/AmazingFeature`)
|
|
322
|
+
3. Commit suas mudanças (`git commit -m 'Add some AmazingFeature'`)
|
|
323
|
+
4. Push para o branch (`git push origin feature/AmazingFeature`)
|
|
324
|
+
5. Abra um Pull Request / Open a Pull Request
|
|
325
|
+
|
|
326
|
+
## 📄 License
|
|
327
|
+
|
|
328
|
+
Este projeto está licenciado sob a Licença MIT - veja o arquivo [LICENSE.txt](LICENSE.txt) para detalhes.
|
|
329
|
+
|
|
330
|
+
This project is licensed under the MIT License - see the [LICENSE.txt](LICENSE.txt) file for details.
|
|
331
|
+
|
|
332
|
+
## 🙏 Acknowledgments
|
|
333
|
+
|
|
334
|
+
Baseado na implementação Python: [brazilian-utils/python](https://github.com/brazilian-utils/python)
|
|
335
|
+
|
|
336
|
+
Based on the Python implementation: [brazilian-utils/python](https://github.com/brazilian-utils/python)
|
|
337
|
+
|
|
338
|
+
## 📞 Support
|
|
339
|
+
|
|
340
|
+
- 🐛 **Issues:** [GitHub Issues](https://github.com/brazilian-utils/ruby/issues)
|
|
341
|
+
- 📖 **Documentation:** [examples/](examples/) folder
|
|
342
|
+
- 💬 **Discussions:** [GitHub Discussions](https://github.com/brazilian-utils/ruby/discussions)
|
|
343
|
+
|
|
344
|
+
---
|
|
345
|
+
|
|
346
|
+
<div align="center">
|
|
347
|
+
Made with ❤️ for the Brazilian Ruby community
|
|
348
|
+
</div>
|
data/Rakefile
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative '../lib/brazilian-utils/boleto-utils'
|
|
4
|
+
|
|
5
|
+
# Examples of using BoletoUtils module
|
|
6
|
+
|
|
7
|
+
puts '=' * 80
|
|
8
|
+
puts 'Boleto Utils - Usage Examples'
|
|
9
|
+
puts '=' * 80
|
|
10
|
+
puts
|
|
11
|
+
|
|
12
|
+
# Example 1: Validating a correct boleto digitable line
|
|
13
|
+
puts '1. Validating a correct boleto digitable line (47 digits):'
|
|
14
|
+
valid_boleto = '00190000090114971860168524522114675860000102656'
|
|
15
|
+
puts " Boleto: #{valid_boleto}"
|
|
16
|
+
puts " Is valid? #{BrazilianUtils::BoletoUtils.is_valid(valid_boleto)}"
|
|
17
|
+
puts
|
|
18
|
+
|
|
19
|
+
# Example 2: Validating a formatted boleto digitable line (with spaces and dots)
|
|
20
|
+
puts '2. Validating a formatted boleto digitable line:'
|
|
21
|
+
formatted_boleto = '0019000009 01149.718601 68524.522114 6 75860000102656'
|
|
22
|
+
puts " Boleto: #{formatted_boleto}"
|
|
23
|
+
puts " Is valid? #{BrazilianUtils::BoletoUtils.is_valid(formatted_boleto)}"
|
|
24
|
+
puts
|
|
25
|
+
|
|
26
|
+
# Example 3: Validating an invalid boleto (wrong first partial check digit)
|
|
27
|
+
puts '3. Validating an invalid boleto (wrong first partial check digit):'
|
|
28
|
+
invalid_boleto_1 = '00190000020114971860168524522114675860000102656'
|
|
29
|
+
puts " Boleto: #{invalid_boleto_1}"
|
|
30
|
+
puts " Is valid? #{BrazilianUtils::BoletoUtils.is_valid(invalid_boleto_1)}"
|
|
31
|
+
puts
|
|
32
|
+
|
|
33
|
+
# Example 4: Validating an invalid boleto (wrong mod11 check digit)
|
|
34
|
+
puts '4. Validating an invalid boleto (wrong mod11 check digit):'
|
|
35
|
+
invalid_boleto_2 = '00190000090114971860168524522114975860000102656'
|
|
36
|
+
puts " Boleto: #{invalid_boleto_2}"
|
|
37
|
+
puts " Is valid? #{BrazilianUtils::BoletoUtils.is_valid(invalid_boleto_2)}"
|
|
38
|
+
puts
|
|
39
|
+
|
|
40
|
+
# Example 5: Validating with empty string
|
|
41
|
+
puts '5. Validating with empty string:'
|
|
42
|
+
puts " Boleto: ''"
|
|
43
|
+
puts " Is valid? #{BrazilianUtils::BoletoUtils.is_valid('')}"
|
|
44
|
+
puts
|
|
45
|
+
|
|
46
|
+
# Example 6: Validating with insufficient length
|
|
47
|
+
puts '6. Validating with insufficient length:'
|
|
48
|
+
short_boleto = '000111'
|
|
49
|
+
puts " Boleto: #{short_boleto}"
|
|
50
|
+
puts " Is valid? #{BrazilianUtils::BoletoUtils.is_valid(short_boleto)}"
|
|
51
|
+
puts
|
|
52
|
+
|
|
53
|
+
# Example 7: Using the alias method 'valid?'
|
|
54
|
+
puts '7. Using the alias method `valid?`:'
|
|
55
|
+
puts " Boleto: #{valid_boleto}"
|
|
56
|
+
puts " Is valid? #{BrazilianUtils::BoletoUtils.valid?(valid_boleto)}"
|
|
57
|
+
puts
|
|
58
|
+
|
|
59
|
+
# Example 8: Validating boleto with various formatting
|
|
60
|
+
puts '8. Validating boleto with dots in different positions:'
|
|
61
|
+
formatted_with_dots = '00190.00009 01149.718601 68524.522114 6 75860000102656'
|
|
62
|
+
puts " Boleto: #{formatted_with_dots}"
|
|
63
|
+
puts " Is valid? #{BrazilianUtils::BoletoUtils.is_valid(formatted_with_dots)}"
|
|
64
|
+
puts
|
|
65
|
+
|
|
66
|
+
puts '=' * 80
|
|
67
|
+
puts 'What is a Boleto Digitable Line?'
|
|
68
|
+
puts '=' * 80
|
|
69
|
+
puts
|
|
70
|
+
puts 'A boleto digitable line (linha digitável) is a 47-digit number that represents'
|
|
71
|
+
puts 'a Brazilian payment slip (boleto bancário). It contains:'
|
|
72
|
+
puts ' - Bank code'
|
|
73
|
+
puts ' - Currency code'
|
|
74
|
+
puts ' - Check digits (mod10 for partials, mod11 for general validation)'
|
|
75
|
+
puts ' - Amount and due date information'
|
|
76
|
+
puts
|
|
77
|
+
puts 'The digitable line is typically formatted with spaces and dots for readability,'
|
|
78
|
+
puts 'but the validation works with the numeric-only version.'
|
|
79
|
+
puts '=' * 80
|