br-utilities 0.0.0 → 1.0.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 +4 -4
- data/CHANGELOG.md +17 -0
- data/LICENSE +9 -0
- data/README.md +1303 -0
- data/README.pt.md +1296 -0
- data/src/br-utilities/br_utils.rb +268 -0
- data/src/br-utilities/cnpj_fmt.rb +18 -0
- data/src/br-utilities/cnpj_gen.rb +18 -0
- data/src/br-utilities/cnpj_utils.rb +8 -0
- data/src/br-utilities/cnpj_val.rb +18 -0
- data/src/br-utilities/cpf_fmt.rb +18 -0
- data/src/br-utilities/cpf_gen.rb +18 -0
- data/src/br-utilities/cpf_utils.rb +8 -0
- data/src/br-utilities/cpf_val.rb +14 -0
- data/src/br-utilities/errors.rb +23 -0
- data/src/br-utilities/version.rb +7 -1
- data/src/br-utilities.rb +34 -6
- metadata +36 -9
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'cpf-utilities'
|
|
4
|
+
require 'cnpj-utilities'
|
|
5
|
+
|
|
6
|
+
require_relative 'errors'
|
|
7
|
+
|
|
8
|
+
# Unified API for Brazilian-related data, like CPF (Cadastro de Pessoa Física)
|
|
9
|
+
# and CNPJ (Cadastro Nacional da Pessoa Jurídica). Provides a unified interface
|
|
10
|
+
# for formatting, generating, and validating data. Aggregates configurable
|
|
11
|
+
# {CpfUtils} and {CnpjUtils} instances behind a single façade.
|
|
12
|
+
#
|
|
13
|
+
# Public API:
|
|
14
|
+
#
|
|
15
|
+
# - {BrUtils.cpf}, {BrUtils.cnpj} — class helpers that alias {BrUtils::DEFAULT}
|
|
16
|
+
# (preferred quick path for domain accessors)
|
|
17
|
+
# - {BrUtils::DEFAULT} — mutable process-wide singleton (JS/Python parity; not
|
|
18
|
+
# thread-isolated — prefer {.new} under concurrency)
|
|
19
|
+
# - {BrUtils#cpf}, {BrUtils#cnpj} — instance accessors with setters
|
|
20
|
+
# - {BrUtils::VERSION}
|
|
21
|
+
# - {BrUtils::InvalidArgumentCombinationError}, {BrUtils::TypeMismatchError}
|
|
22
|
+
#
|
|
23
|
+
# Two-tier access: main-class shortcuts ({BrUtils::CpfFormatter}, etc.) and
|
|
24
|
+
# nested package modules ({BrUtils::CpfFmt}, {BrUtils::CpfUtils}, etc.). Root
|
|
25
|
+
# siblings ({CpfUtils}, {CnpjUtils}, {CpfFmt}, …) remain loadable after
|
|
26
|
+
# +require 'br-utilities'+.
|
|
27
|
+
#
|
|
28
|
+
# Mutating {BrUtils::DEFAULT} (e.g. via setters) affects subsequent class-helper
|
|
29
|
+
# calls process-wide (shared across threads). Prefer {BrUtils.new} for concurrent
|
|
30
|
+
# or isolated work. Custom instances are independent of +DEFAULT+.
|
|
31
|
+
#
|
|
32
|
+
# @example
|
|
33
|
+
# require 'br-utilities'
|
|
34
|
+
#
|
|
35
|
+
# BrUtils.cpf.format('12345678909') # => "123.456.789-09"
|
|
36
|
+
# BrUtils.cnpj.is_valid('91415732000793') # => true
|
|
37
|
+
class BrUtils
|
|
38
|
+
SETTINGS_KEYS = %i[cpf cnpj].freeze
|
|
39
|
+
FLAT_KEYS = %i[cpf_formatter cpf_generator cnpj_formatter cnpj_generator cnpj_validator].freeze
|
|
40
|
+
KEYWORD_KEYS = (SETTINGS_KEYS + FLAT_KEYS).freeze
|
|
41
|
+
|
|
42
|
+
private_constant :SETTINGS_KEYS, :FLAT_KEYS, :KEYWORD_KEYS
|
|
43
|
+
|
|
44
|
+
# Internal helpers for resolving domain utils from settings / keyword arguments.
|
|
45
|
+
module Helpers
|
|
46
|
+
module_function
|
|
47
|
+
|
|
48
|
+
def resolve_settings(settings, keywords)
|
|
49
|
+
keyword_settings = compact_keywords(keywords)
|
|
50
|
+
raise_ambiguous_settings! if !settings.nil? && !keyword_settings.empty?
|
|
51
|
+
return normalize_settings(settings) unless settings.nil?
|
|
52
|
+
|
|
53
|
+
keyword_settings
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def normalize_settings(settings)
|
|
57
|
+
raise TypeMismatchError, "BrUtils settings must be a Hash. Got #{settings.class}." unless settings.is_a?(Hash)
|
|
58
|
+
|
|
59
|
+
SETTINGS_KEYS.each_with_object({}) do |key, resolved|
|
|
60
|
+
if settings.key?(key)
|
|
61
|
+
resolved[key] = settings[key]
|
|
62
|
+
elsif settings.key?(key.to_s)
|
|
63
|
+
resolved[key] = settings[key.to_s]
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def compact_keywords(keywords)
|
|
69
|
+
KEYWORD_KEYS.each_with_object({}) do |key, resolved|
|
|
70
|
+
value = keywords[key]
|
|
71
|
+
resolved[key] = value unless value.nil?
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def resolve_cpf_utils(resolved)
|
|
76
|
+
return resolve_utils(CpfUtils, resolved[:cpf]) if resolved.key?(:cpf)
|
|
77
|
+
return CpfUtils.new unless cpf_flat?(resolved)
|
|
78
|
+
|
|
79
|
+
CpfUtils.new(formatter: resolved[:cpf_formatter], generator: resolved[:cpf_generator])
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def cpf_flat?(resolved)
|
|
83
|
+
resolved.key?(:cpf_formatter) || resolved.key?(:cpf_generator)
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def resolve_cnpj_utils(resolved)
|
|
87
|
+
return resolve_utils(CnpjUtils, resolved[:cnpj]) if resolved.key?(:cnpj)
|
|
88
|
+
return CnpjUtils.new unless cnpj_flat?(resolved)
|
|
89
|
+
|
|
90
|
+
CnpjUtils.new(
|
|
91
|
+
formatter: resolved[:cnpj_formatter],
|
|
92
|
+
generator: resolved[:cnpj_generator],
|
|
93
|
+
validator: resolved[:cnpj_validator]
|
|
94
|
+
)
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def cnpj_flat?(resolved)
|
|
98
|
+
resolved.key?(:cnpj_formatter) || resolved.key?(:cnpj_generator) || resolved.key?(:cnpj_validator)
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def resolve_utils(utils_cls, value)
|
|
102
|
+
return utils_cls.new if value.nil?
|
|
103
|
+
return value if value.is_a?(utils_cls)
|
|
104
|
+
return utils_cls.new(value) if value.is_a?(Hash)
|
|
105
|
+
|
|
106
|
+
# Duck-typed / test doubles: use the given object by reference (Python parity).
|
|
107
|
+
value
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def raise_ambiguous_settings!
|
|
111
|
+
option_keywords = KEYWORD_KEYS.map { |key| "#{key}:" }.join(', ')
|
|
112
|
+
|
|
113
|
+
raise InvalidArgumentCombinationError,
|
|
114
|
+
'Pass either a settings Hash to `settings`, or keyword arguments ' \
|
|
115
|
+
"(#{option_keywords}), not both."
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
private_constant :Helpers
|
|
119
|
+
|
|
120
|
+
# Creates a new {BrUtils} instance with customized options. All options are
|
|
121
|
+
# optional. If any option is omitted, it falls back to its default value.
|
|
122
|
+
#
|
|
123
|
+
# Each of +:cpf+ and +:cnpj+ accepts either a pre-built utils instance or a
|
|
124
|
+
# configuration {Hash} spread into the corresponding {CpfUtils} / {CnpjUtils}
|
|
125
|
+
# constructor. Within that Hash, each resource key (+formatter+, +generator+,
|
|
126
|
+
# and +validator+ for CNPJ) accepts either an options object or a mapping of
|
|
127
|
+
# option values.
|
|
128
|
+
#
|
|
129
|
+
# Flat +:cpf_formatter+ / +:cpf_generator+ and +:cnpj_formatter+ /
|
|
130
|
+
# +:cnpj_generator+ / +:cnpj_validator+ arguments are supported as a
|
|
131
|
+
# convenience when only individual components need customization. They are
|
|
132
|
+
# ignored when the corresponding +:cpf+ or +:cnpj+ argument is provided.
|
|
133
|
+
#
|
|
134
|
+
# +settings+ and the keyword arguments are never merged with each other: when
|
|
135
|
+
# +settings+ is given (a {Hash} with +:cpf+ and/or +:cnpj+ keys), it alone
|
|
136
|
+
# determines the domains; otherwise, the domains are built exclusively from the
|
|
137
|
+
# keyword arguments. Passing +settings+ together with any non-+nil+ keyword
|
|
138
|
+
# argument raises {InvalidArgumentCombinationError} instead of silently
|
|
139
|
+
# ignoring the keywords.
|
|
140
|
+
#
|
|
141
|
+
# @param settings [Hash, nil] settings Hash with +:cpf+ and/or +:cnpj+ keys
|
|
142
|
+
# (each a utils instance, settings Hash, or +nil+)
|
|
143
|
+
# @param keywords [Hash] +:cpf+, +:cnpj+, and/or flat component kwargs
|
|
144
|
+
# (mutually exclusive with +settings+)
|
|
145
|
+
# @raise [InvalidArgumentCombinationError] if +settings+ and a keyword argument
|
|
146
|
+
# are both given
|
|
147
|
+
# @raise [TypeMismatchError] if +settings+ is given and is not a +Hash+
|
|
148
|
+
# @raise [CnpjFmt::TypeMismatchError] if CNPJ formatter options have an invalid
|
|
149
|
+
# type
|
|
150
|
+
# @raise [CnpjFmt::OutOfRangeError] if CNPJ formatter +hidden_start+ or
|
|
151
|
+
# +hidden_end+ are out of valid range
|
|
152
|
+
# @raise [CnpjFmt::ValidationError] if any CNPJ formatter key option contains a
|
|
153
|
+
# disallowed character
|
|
154
|
+
# @raise [CnpjGen::TypeMismatchError] if CNPJ generator options have an invalid
|
|
155
|
+
# type
|
|
156
|
+
# @raise [CnpjGen::ValidationError] if CNPJ generator +prefix+ is invalid or
|
|
157
|
+
# +type+ is not allowed
|
|
158
|
+
# @raise [CnpjVal::TypeMismatchError] if CNPJ validator options have an invalid
|
|
159
|
+
# type
|
|
160
|
+
# @raise [CnpjVal::ValidationError] if CNPJ validator +type+ is not allowed
|
|
161
|
+
# @raise [CpfFmt::TypeMismatchError] if CPF formatter options have an invalid
|
|
162
|
+
# type
|
|
163
|
+
# @raise [CpfFmt::OutOfRangeError] if CPF formatter +hidden_start+ or
|
|
164
|
+
# +hidden_end+ are out of valid range
|
|
165
|
+
# @raise [CpfFmt::ValidationError] if any CPF formatter key option contains a
|
|
166
|
+
# disallowed character
|
|
167
|
+
# @raise [CpfGen::TypeMismatchError] if CPF generator options have an invalid
|
|
168
|
+
# type
|
|
169
|
+
# @raise [CpfGen::ValidationError] if CPF generator +prefix+ is invalid
|
|
170
|
+
def initialize(settings = nil, **keywords)
|
|
171
|
+
resolved = Helpers.resolve_settings(settings, keywords)
|
|
172
|
+
|
|
173
|
+
@cpf = Helpers.resolve_cpf_utils(resolved)
|
|
174
|
+
@cnpj = Helpers.resolve_cnpj_utils(resolved)
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
# Access the CPF utilities instance.
|
|
178
|
+
#
|
|
179
|
+
# @return [CpfUtils]
|
|
180
|
+
attr_reader :cpf
|
|
181
|
+
|
|
182
|
+
# Access the CNPJ utilities instance.
|
|
183
|
+
#
|
|
184
|
+
# @return [CnpjUtils]
|
|
185
|
+
attr_reader :cnpj
|
|
186
|
+
|
|
187
|
+
# Sets the active CPF utilities instance.
|
|
188
|
+
#
|
|
189
|
+
# It is flexible and can handle any of these inputs:
|
|
190
|
+
#
|
|
191
|
+
# 1. A complete new instance of {CpfUtils}
|
|
192
|
+
# 2. A {Hash} of {CpfUtils} component settings
|
|
193
|
+
# 3. A partial {Hash} with options for the CPF utilities
|
|
194
|
+
# 4. +nil+ creates a brand new instance of {CpfUtils} with the default options
|
|
195
|
+
#
|
|
196
|
+
# Note that this resets the CPF utilities instance completely. Any previous
|
|
197
|
+
# options will be overridden. To alter only a single option or a few options
|
|
198
|
+
# of the existing instance, access it directly and use the CPF utilities'
|
|
199
|
+
# setters and methods (e.g. +utils.cpf.formatter.options.hidden = true+).
|
|
200
|
+
#
|
|
201
|
+
# @param value [CpfUtils, Hash, nil]
|
|
202
|
+
# @raise [CpfFmt::TypeMismatchError] if formatter options have an invalid type
|
|
203
|
+
# @raise [CpfFmt::OutOfRangeError] if formatter +hidden_start+ or +hidden_end+
|
|
204
|
+
# are out of valid range
|
|
205
|
+
# @raise [CpfFmt::ValidationError] if any formatter key option contains a
|
|
206
|
+
# disallowed character
|
|
207
|
+
# @raise [CpfGen::TypeMismatchError] if generator options have an invalid type
|
|
208
|
+
# @raise [CpfGen::ValidationError] if generator +prefix+ is invalid
|
|
209
|
+
def cpf=(value)
|
|
210
|
+
@cpf = Helpers.resolve_utils(CpfUtils, value)
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
# Sets the active CNPJ utilities instance.
|
|
214
|
+
#
|
|
215
|
+
# It is flexible and can handle any of these inputs:
|
|
216
|
+
#
|
|
217
|
+
# 1. A complete new instance of {CnpjUtils}
|
|
218
|
+
# 2. A {Hash} of {CnpjUtils} component settings
|
|
219
|
+
# 3. A partial {Hash} with options for the CNPJ utilities
|
|
220
|
+
# 4. +nil+ creates a brand new instance of {CnpjUtils} with the default options
|
|
221
|
+
#
|
|
222
|
+
# Note that this resets the CNPJ utilities instance completely. Any previous
|
|
223
|
+
# options will be overridden. To alter only a single option or a few options
|
|
224
|
+
# of the existing instance, access it directly and use the CNPJ utilities'
|
|
225
|
+
# setters and methods (e.g. +utils.cnpj.generator.options.type = 'numeric'+).
|
|
226
|
+
#
|
|
227
|
+
# @param value [CnpjUtils, Hash, nil]
|
|
228
|
+
# @raise [CnpjFmt::TypeMismatchError] if formatter options have an invalid type
|
|
229
|
+
# @raise [CnpjFmt::OutOfRangeError] if formatter +hidden_start+ or +hidden_end+
|
|
230
|
+
# are out of valid range
|
|
231
|
+
# @raise [CnpjFmt::ValidationError] if any formatter key option contains a
|
|
232
|
+
# disallowed character
|
|
233
|
+
# @raise [CnpjGen::TypeMismatchError] if generator options have an invalid type
|
|
234
|
+
# @raise [CnpjGen::ValidationError] if generator +prefix+ is invalid or +type+
|
|
235
|
+
# is not allowed
|
|
236
|
+
# @raise [CnpjVal::TypeMismatchError] if validator options have an invalid type
|
|
237
|
+
# @raise [CnpjVal::ValidationError] if validator +type+ is not allowed
|
|
238
|
+
def cnpj=(value)
|
|
239
|
+
@cnpj = Helpers.resolve_utils(CnpjUtils, value)
|
|
240
|
+
end
|
|
241
|
+
|
|
242
|
+
# Default {BrUtils} instance with default CPF and CNPJ utilities (parity with
|
|
243
|
+
# the JS default export / Python +br_utils+ singleton). Configuration is
|
|
244
|
+
# process-wide and shared across threads: mutating this instance (e.g. via
|
|
245
|
+
# setters) affects subsequent {BrUtils.cpf} and {BrUtils.cnpj} calls for every
|
|
246
|
+
# caller in the process. Prefer {BrUtils.new} for threaded or isolated work.
|
|
247
|
+
DEFAULT = new
|
|
248
|
+
|
|
249
|
+
class << self
|
|
250
|
+
# Access the CPF utilities from {DEFAULT} (alias of {BrUtils#cpf} on that
|
|
251
|
+
# instance).
|
|
252
|
+
#
|
|
253
|
+
# @return [CpfUtils]
|
|
254
|
+
# @see BrUtils#cpf
|
|
255
|
+
def cpf
|
|
256
|
+
DEFAULT.cpf
|
|
257
|
+
end
|
|
258
|
+
|
|
259
|
+
# Access the CNPJ utilities from {DEFAULT} (alias of {BrUtils#cnpj} on that
|
|
260
|
+
# instance).
|
|
261
|
+
#
|
|
262
|
+
# @return [CnpjUtils]
|
|
263
|
+
# @see BrUtils#cnpj
|
|
264
|
+
def cnpj
|
|
265
|
+
DEFAULT.cnpj
|
|
266
|
+
end
|
|
267
|
+
end
|
|
268
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class BrUtils
|
|
4
|
+
# CNPJ formatting utilities re-exported from +cnpj-fmt+ (via +cnpj-utilities+).
|
|
5
|
+
#
|
|
6
|
+
# Nested package module — same object as +::CnpjFmt+ (Options, helpers, errors,
|
|
7
|
+
# types).
|
|
8
|
+
CnpjFmt = ::CnpjFmt
|
|
9
|
+
|
|
10
|
+
# Main-class shortcut for {CnpjFmt::CnpjFormatter}.
|
|
11
|
+
CnpjFormatter = CnpjFmt::CnpjFormatter
|
|
12
|
+
|
|
13
|
+
# Main-class shortcut for {CnpjFmt::CnpjFormatterOptions}.
|
|
14
|
+
CnpjFormatterOptions = CnpjFmt::CnpjFormatterOptions
|
|
15
|
+
|
|
16
|
+
# Main-class shortcut for {CnpjFmt::Error}.
|
|
17
|
+
CnpjFormatterError = CnpjFmt::Error
|
|
18
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class BrUtils
|
|
4
|
+
# CNPJ generation utilities re-exported from +cnpj-gen+ (via +cnpj-utilities+).
|
|
5
|
+
#
|
|
6
|
+
# Nested package module — same object as +::CnpjGen+ (Options, helpers, errors,
|
|
7
|
+
# types).
|
|
8
|
+
CnpjGen = ::CnpjGen
|
|
9
|
+
|
|
10
|
+
# Main-class shortcut for {CnpjGen::CnpjGenerator}.
|
|
11
|
+
CnpjGenerator = CnpjGen::CnpjGenerator
|
|
12
|
+
|
|
13
|
+
# Main-class shortcut for {CnpjGen::CnpjGeneratorOptions}.
|
|
14
|
+
CnpjGeneratorOptions = CnpjGen::CnpjGeneratorOptions
|
|
15
|
+
|
|
16
|
+
# Main-class shortcut for {CnpjGen::Error}.
|
|
17
|
+
CnpjGeneratorError = CnpjGen::Error
|
|
18
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class BrUtils
|
|
4
|
+
# CNPJ validation utilities re-exported from +cnpj-val+ (via +cnpj-utilities+).
|
|
5
|
+
#
|
|
6
|
+
# Nested package module — same object as +::CnpjVal+ (Options, helpers, errors,
|
|
7
|
+
# types).
|
|
8
|
+
CnpjVal = ::CnpjVal
|
|
9
|
+
|
|
10
|
+
# Main-class shortcut for {CnpjVal::CnpjValidator}.
|
|
11
|
+
CnpjValidator = CnpjVal::CnpjValidator
|
|
12
|
+
|
|
13
|
+
# Main-class shortcut for {CnpjVal::CnpjValidatorOptions}.
|
|
14
|
+
CnpjValidatorOptions = CnpjVal::CnpjValidatorOptions
|
|
15
|
+
|
|
16
|
+
# Main-class shortcut for {CnpjVal::Error}.
|
|
17
|
+
CnpjValidatorError = CnpjVal::Error
|
|
18
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class BrUtils
|
|
4
|
+
# CPF formatting utilities re-exported from +cpf-fmt+ (via +cpf-utilities+).
|
|
5
|
+
#
|
|
6
|
+
# Nested package module — same object as +::CpfFmt+ (Options, helpers, errors,
|
|
7
|
+
# types).
|
|
8
|
+
CpfFmt = ::CpfFmt
|
|
9
|
+
|
|
10
|
+
# Main-class shortcut for {CpfFmt::CpfFormatter}.
|
|
11
|
+
CpfFormatter = CpfFmt::CpfFormatter
|
|
12
|
+
|
|
13
|
+
# Main-class shortcut for {CpfFmt::CpfFormatterOptions}.
|
|
14
|
+
CpfFormatterOptions = CpfFmt::CpfFormatterOptions
|
|
15
|
+
|
|
16
|
+
# Main-class shortcut for {CpfFmt::Error}.
|
|
17
|
+
CpfFormatterError = CpfFmt::Error
|
|
18
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class BrUtils
|
|
4
|
+
# CPF generation utilities re-exported from +cpf-gen+ (via +cpf-utilities+).
|
|
5
|
+
#
|
|
6
|
+
# Nested package module — same object as +::CpfGen+ (Options, helpers, errors,
|
|
7
|
+
# types).
|
|
8
|
+
CpfGen = ::CpfGen
|
|
9
|
+
|
|
10
|
+
# Main-class shortcut for {CpfGen::CpfGenerator}.
|
|
11
|
+
CpfGenerator = CpfGen::CpfGenerator
|
|
12
|
+
|
|
13
|
+
# Main-class shortcut for {CpfGen::CpfGeneratorOptions}.
|
|
14
|
+
CpfGeneratorOptions = CpfGen::CpfGeneratorOptions
|
|
15
|
+
|
|
16
|
+
# Main-class shortcut for {CpfGen::Error}.
|
|
17
|
+
CpfGeneratorError = CpfGen::Error
|
|
18
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class BrUtils
|
|
4
|
+
# CPF validation utilities re-exported from +cpf-val+ (via +cpf-utilities+).
|
|
5
|
+
#
|
|
6
|
+
# Nested package module — same object as +::CpfVal+ (helpers, errors, types).
|
|
7
|
+
CpfVal = ::CpfVal
|
|
8
|
+
|
|
9
|
+
# Main-class shortcut for {CpfVal::CpfValidator}.
|
|
10
|
+
CpfValidator = CpfVal::CpfValidator
|
|
11
|
+
|
|
12
|
+
# Main-class shortcut for {CpfVal::Error}.
|
|
13
|
+
CpfValidatorError = CpfVal::Error
|
|
14
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class BrUtils
|
|
4
|
+
# Marker module mixed into every custom error raised by this library.
|
|
5
|
+
#
|
|
6
|
+
# Use +rescue BrUtils::Error+ to catch every library error regardless of
|
|
7
|
+
# native ancestry. Domain packages raise their own error hierarchies;
|
|
8
|
+
# this gem only defines the misuse errors it raises itself.
|
|
9
|
+
module Error; end
|
|
10
|
+
|
|
11
|
+
# API misuse error raised when an argument's runtime type does not match the
|
|
12
|
+
# type required by the API contract (for example, a non-Hash +settings+ value).
|
|
13
|
+
class TypeMismatchError < TypeError
|
|
14
|
+
include Error
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# API misuse error raised when the combination of provided arguments does not
|
|
18
|
+
# match any valid overload-style signature (for example, a settings Hash
|
|
19
|
+
# together with keyword overrides).
|
|
20
|
+
class InvalidArgumentCombinationError < ArgumentError
|
|
21
|
+
include Error
|
|
22
|
+
end
|
|
23
|
+
end
|
data/src/br-utilities/version.rb
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
# Placeholder module so the gemspec (and any early require of this file) can read
|
|
4
|
+
# {BrUtils::VERSION}. The gem entry point promotes +BrUtils+ to a class and
|
|
5
|
+
# reopens it for the façade implementation.
|
|
3
6
|
module BrUtils
|
|
4
|
-
|
|
7
|
+
# Gem version string. Placeholder replaced at build/publish time.
|
|
8
|
+
#
|
|
9
|
+
# @return [String]
|
|
10
|
+
VERSION = '1.0.0'
|
|
5
11
|
end
|
data/src/br-utilities.rb
CHANGED
|
@@ -1,11 +1,39 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
4
|
-
require
|
|
3
|
+
require 'cpf-utilities'
|
|
4
|
+
require 'cnpj-utilities'
|
|
5
5
|
require_relative 'br-utilities/version'
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
# Entry point for the +br-utilities+ gem.
|
|
8
|
+
#
|
|
9
|
+
# Loads sibling packages (+cpf-utilities+, +cnpj-utilities+) and defines the
|
|
10
|
+
# {BrUtils} façade class. +version.rb+ defines a placeholder module so the
|
|
11
|
+
# gemspec can read {BrUtils::VERSION}; this file promotes it to the class
|
|
12
|
+
# consumers instantiate.
|
|
13
|
+
#
|
|
14
|
+
# Two-tier access after +require 'br-utilities'+:
|
|
15
|
+
#
|
|
16
|
+
# - *Main shortcuts* at the façade root: {BrUtils::CpfFormatter},
|
|
17
|
+
# {BrUtils::CnpjFormatter}, etc.
|
|
18
|
+
# - *Package nests* for the full sibling surface (Options, helpers, errors,
|
|
19
|
+
# types): {BrUtils::CpfFmt}, {BrUtils::CnpjUtils}, etc. (same objects as
|
|
20
|
+
# +::CpfFmt+, +::CnpjUtils+, …).
|
|
21
|
+
# - Root siblings (+CpfUtils+, +CnpjUtils+, +CpfFmt+, …) remain supported
|
|
22
|
+
# unchanged.
|
|
23
|
+
unless BrUtils.is_a?(Class)
|
|
24
|
+
version = BrUtils::VERSION
|
|
25
|
+
Object.send(:remove_const, :BrUtils)
|
|
26
|
+
BrUtils = Class.new
|
|
27
|
+
BrUtils.const_set(:VERSION, version)
|
|
11
28
|
end
|
|
29
|
+
|
|
30
|
+
require_relative 'br-utilities/errors'
|
|
31
|
+
require_relative 'br-utilities/br_utils'
|
|
32
|
+
require_relative 'br-utilities/cpf_fmt'
|
|
33
|
+
require_relative 'br-utilities/cpf_gen'
|
|
34
|
+
require_relative 'br-utilities/cpf_val'
|
|
35
|
+
require_relative 'br-utilities/cpf_utils'
|
|
36
|
+
require_relative 'br-utilities/cnpj_fmt'
|
|
37
|
+
require_relative 'br-utilities/cnpj_gen'
|
|
38
|
+
require_relative 'br-utilities/cnpj_val'
|
|
39
|
+
require_relative 'br-utilities/cnpj_utils'
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: br-utilities
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 1.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Julio L. Muller
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-08-21 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: cnpj-utilities
|
|
@@ -16,35 +16,62 @@ dependencies:
|
|
|
16
16
|
requirements:
|
|
17
17
|
- - ">="
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version:
|
|
19
|
+
version: 1.0.0
|
|
20
|
+
- - "<"
|
|
21
|
+
- !ruby/object:Gem::Version
|
|
22
|
+
version: 1.1.0
|
|
20
23
|
type: :runtime
|
|
21
24
|
prerelease: false
|
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
26
|
requirements:
|
|
24
27
|
- - ">="
|
|
25
28
|
- !ruby/object:Gem::Version
|
|
26
|
-
version:
|
|
29
|
+
version: 1.0.0
|
|
30
|
+
- - "<"
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: 1.1.0
|
|
27
33
|
- !ruby/object:Gem::Dependency
|
|
28
34
|
name: cpf-utilities
|
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
|
30
36
|
requirements:
|
|
31
37
|
- - ">="
|
|
32
38
|
- !ruby/object:Gem::Version
|
|
33
|
-
version:
|
|
39
|
+
version: 1.0.0
|
|
40
|
+
- - "<"
|
|
41
|
+
- !ruby/object:Gem::Version
|
|
42
|
+
version: 1.1.0
|
|
34
43
|
type: :runtime
|
|
35
44
|
prerelease: false
|
|
36
45
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
46
|
requirements:
|
|
38
47
|
- - ">="
|
|
39
48
|
- !ruby/object:Gem::Version
|
|
40
|
-
version:
|
|
41
|
-
|
|
49
|
+
version: 1.0.0
|
|
50
|
+
- - "<"
|
|
51
|
+
- !ruby/object:Gem::Version
|
|
52
|
+
version: 1.1.0
|
|
53
|
+
description: Utilities to deal with Brazilian-related data
|
|
42
54
|
email:
|
|
55
|
+
- juliolmuller@outlook.com
|
|
43
56
|
executables: []
|
|
44
57
|
extensions: []
|
|
45
58
|
extra_rdoc_files: []
|
|
46
59
|
files:
|
|
60
|
+
- CHANGELOG.md
|
|
61
|
+
- LICENSE
|
|
62
|
+
- README.md
|
|
63
|
+
- README.pt.md
|
|
47
64
|
- src/br-utilities.rb
|
|
65
|
+
- src/br-utilities/br_utils.rb
|
|
66
|
+
- src/br-utilities/cnpj_fmt.rb
|
|
67
|
+
- src/br-utilities/cnpj_gen.rb
|
|
68
|
+
- src/br-utilities/cnpj_utils.rb
|
|
69
|
+
- src/br-utilities/cnpj_val.rb
|
|
70
|
+
- src/br-utilities/cpf_fmt.rb
|
|
71
|
+
- src/br-utilities/cpf_gen.rb
|
|
72
|
+
- src/br-utilities/cpf_utils.rb
|
|
73
|
+
- src/br-utilities/cpf_val.rb
|
|
74
|
+
- src/br-utilities/errors.rb
|
|
48
75
|
- src/br-utilities/version.rb
|
|
49
76
|
homepage: https://github.com/LacusSolutions/br-utils-ruby
|
|
50
77
|
licenses:
|
|
@@ -60,7 +87,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
60
87
|
requirements:
|
|
61
88
|
- - ">="
|
|
62
89
|
- !ruby/object:Gem::Version
|
|
63
|
-
version: '3.
|
|
90
|
+
version: '3.1'
|
|
64
91
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
65
92
|
requirements:
|
|
66
93
|
- - ">="
|
|
@@ -70,5 +97,5 @@ requirements: []
|
|
|
70
97
|
rubygems_version: 3.4.19
|
|
71
98
|
signing_key:
|
|
72
99
|
specification_version: 4
|
|
73
|
-
summary:
|
|
100
|
+
summary: Utilities to deal with Brazilian-related data
|
|
74
101
|
test_files: []
|