lacus-utils 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 55e2230dbc3093059a4cde7f74cac60ef27e2183bfc033b6f6d90bde601c81ec
4
+ data.tar.gz: d9f57500daeee5558f97b260f4fdc6338c854e76bd745f4b00b75ba0c2c81a2a
5
+ SHA512:
6
+ metadata.gz: 8b5a1b1ce6f2317fe66916fdc8aae1534f94185b3b01c5491df497fc71ca3b997a9146e6e72437d702a62039df51dcc589d749ced638534a9cd46f19130b603a
7
+ data.tar.gz: f11bf35f4ee395cd388942a62e15d2e0cc57a36a2106faab112e54abb3faf40e897f1ced6bc82764fbc830c4cdb3657f4173e140a82e57a0535d64a9c5922e0a
data/LICENSE ADDED
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Julio L. Muller
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,144 @@
1
+ # Lacus Solutions' Utils
2
+
3
+ [![Gem Version](https://img.shields.io/gem/v/lacus-utils)](https://rubygems.org/gems/lacus-utils)
4
+ [![Downloads Count](https://img.shields.io/gem/dt/lacus-utils)](https://rubygems.org/gems/lacus-utils)
5
+ [![Ruby Version](https://img.shields.io/badge/ruby-%3E%3D%203.2-CC342D?logo=ruby&logoColor=white)](https://www.ruby-lang.org/)
6
+ [![Test Status](https://img.shields.io/github/actions/workflow/status/LacusSolutions/br-utils-ruby/ci.yml?label=ci/cd)](https://github.com/LacusSolutions/br-utils-ruby/actions)
7
+ [![Last Update Date](https://img.shields.io/github/last-commit/LacusSolutions/br-utils-ruby)](https://github.com/LacusSolutions/br-utils-ruby)
8
+ [![Project License](https://img.shields.io/github/license/LacusSolutions/br-utils-ruby)](https://github.com/LacusSolutions/br-utils-ruby/blob/main/LICENSE)
9
+
10
+ A Ruby reusable utilities library for Lacus Solutions' packages.
11
+
12
+ ## Ruby Support
13
+
14
+ | ![Ruby 3.2](https://img.shields.io/badge/Ruby-3.2-CC342D?logo=ruby&logoColor=white) | ![Ruby 3.3](https://img.shields.io/badge/Ruby-3.3-CC342D?logo=ruby&logoColor=white) | ![Ruby 3.4](https://img.shields.io/badge/Ruby-3.4-CC342D?logo=ruby&logoColor=white) |
15
+ |--- | --- | --- |
16
+ | Passing ✔ | Passing ✔ | Passing ✔ |
17
+
18
+ ## Features
19
+
20
+ - **Type description**: Ruby-native type labels for error messages (`nil`, `hash`, `symbol`, built-ins, arrays, `NaN`, `Infinity`)
21
+ - **Random sequences**: Generate numeric, alphabetic, or alphanumeric sequences of any length using a cryptographically secure RNG
22
+ - **Zero dependencies**: No external runtime dependencies
23
+
24
+ ## Installation
25
+
26
+ Install the gem directly:
27
+
28
+ ```bash
29
+ gem install lacus-utils
30
+ ```
31
+
32
+ Or add it to your `Gemfile` and run `bundle install`:
33
+
34
+ ```ruby
35
+ gem 'lacus-utils'
36
+ ```
37
+
38
+ ## Require
39
+
40
+ ```ruby
41
+ require 'lacus-utils'
42
+ ```
43
+
44
+ ## Quick Start
45
+
46
+ ```ruby
47
+ require 'lacus-utils'
48
+
49
+ LacusUtils.describe_type(nil) # => 'nil'
50
+ LacusUtils.describe_type('hello') # => 'string'
51
+ LacusUtils.describe_type(42) # => 'integer number'
52
+ LacusUtils.describe_type(3.14) # => 'float number'
53
+ LacusUtils.describe_type([1, 2, 3]) # => 'number[]'
54
+ LacusUtils.describe_type([1, 'a', 2]) # => '(number | string)[]'
55
+ LacusUtils.describe_type({}) # => 'hash'
56
+
57
+ LacusUtils.generate_random_sequence(10, :numeric) # => e.g. '9956000611'
58
+ LacusUtils.generate_random_sequence(6, :alphabetic) # => e.g. 'AXQMZB'
59
+ LacusUtils.generate_random_sequence(8, :alphanumeric) # => e.g. '8ZFB2K09'
60
+ LacusUtils.generate_random_sequence(8) # => e.g. '8ZFB2K09' (alphanumeric)
61
+ ```
62
+
63
+ ## API
64
+
65
+ All entry points are module functions on `LacusUtils`, implemented in [`src/`](src/) and covered by tests in [`tests/`](tests/).
66
+
67
+ ### `LacusUtils.describe_type(value) -> String`
68
+
69
+ Describes the type of a value for error messages. Pure, deterministic, and never raises.
70
+
71
+ | Input | Result |
72
+ |--------|--------|
73
+ | `nil` | `'nil'` |
74
+ | `String` | `'string'` |
75
+ | `true` / `false` | `'boolean'` |
76
+ | `Integer` | `'integer number'` |
77
+ | `Float` (finite) | `'float number'` |
78
+ | `Float::NAN` | `'NaN'` |
79
+ | `Float::INFINITY` / `-Float::INFINITY` | `'Infinity'` |
80
+ | `Complex` | `'complex number'` |
81
+ | `Rational` | `'rational number'` |
82
+ | `Symbol` | `'symbol'` |
83
+ | `Hash` | `'hash'` |
84
+ | `Set` | `'set'` |
85
+ | `Proc` / `Method` | `'function'` |
86
+ | `Class` / `Module` | `'class'` |
87
+ | custom object | `'object'` |
88
+ | `[]` | `'Array (empty)'` |
89
+ | `[1, 2, 3]` | `'number[]'` |
90
+ | `[1, 'a', 2]` | `'(number \| string)[]'` |
91
+
92
+ Inside an array, numeric values collapse to `'number'`, and the union of element types preserves first-seen order (it is **not** sorted).
93
+
94
+ ### `LacusUtils.generate_random_sequence(size, type = :alphanumeric) -> String`
95
+
96
+ Generates a random character sequence of the given length and type, drawn using a cryptographically secure RNG (`SecureRandom`).
97
+
98
+ - **`size`**: `Integer` — length of the sequence (e.g. `10`). `0` returns `''`.
99
+ - **`type`**: `Symbol` — character set to draw from (defaults to `:alphanumeric`). One of:
100
+ - **`:numeric`**: digits `0-9`
101
+ - **`:alphabetic`**: uppercase letters `A-Z`
102
+ - **`:alphanumeric`**: digits and uppercase letters `0-9A-Z`
103
+
104
+ ```ruby
105
+ LacusUtils.generate_random_sequence(10, :numeric) # => e.g. '9956000611'
106
+ LacusUtils.generate_random_sequence(6, :alphabetic) # => e.g. 'AXQMZB'
107
+ LacusUtils.generate_random_sequence(8) # => e.g. '8ZFB2K09' (alphanumeric)
108
+ LacusUtils.generate_random_sequence(0) # => ''
109
+ ```
110
+
111
+ Raises `ArgumentError` when `size` is negative, and `ArgumentError` when `type` is not one of the three known kinds:
112
+
113
+ ```ruby
114
+ LacusUtils.generate_random_sequence(-1) # => ArgumentError: size must be non-negative, got -1
115
+ LacusUtils.generate_random_sequence(4, :foo) # => ArgumentError: unknown sequence type: :foo
116
+ ```
117
+
118
+ ### Exports summary
119
+
120
+ | Method | Description |
121
+ |--------|-------------|
122
+ | `describe_type(value)` | Type description for error messages |
123
+ | `generate_random_sequence(size, type = :alphanumeric)` | Random sequence generation |
124
+
125
+ ## Contribution & Support
126
+
127
+ We welcome contributions! Please see our [Contributing Guidelines](https://github.com/LacusSolutions/br-utils-ruby/blob/main/CONTRIBUTING.md) for details. If you find this project helpful, please consider:
128
+
129
+ - ⭐ Starring the repository
130
+ - 🤝 Contributing to the codebase
131
+ - 💡 [Suggesting new features](https://github.com/LacusSolutions/br-utils-ruby/issues)
132
+ - 🐛 [Reporting bugs](https://github.com/LacusSolutions/br-utils-ruby/issues)
133
+
134
+ ## License
135
+
136
+ This project is licensed under the MIT License - see the [LICENSE](https://github.com/LacusSolutions/br-utils-ruby/blob/main/LICENSE) file for details.
137
+
138
+ ## Changelog
139
+
140
+ See [CHANGELOG](./CHANGELOG.md) for a list of changes and version history.
141
+
142
+ ---
143
+
144
+ Made with ❤️ by [Lacus Solutions](https://github.com/LacusSolutions)
@@ -0,0 +1,97 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LacusUtils
4
+ # Describes the type of a value for error messages. Returns a short
5
+ # human-readable string describing the runtime type of the value. Pure,
6
+ # deterministic, and never raises.
7
+ #
8
+ # @param value [Object] any value to describe
9
+ # @return [String] a human-readable type label
10
+ #
11
+ # @example
12
+ # LacusUtils.describe_type(nil) # => 'nil'
13
+ # LacusUtils.describe_type('hello') # => 'string'
14
+ # LacusUtils.describe_type(true) # => 'boolean'
15
+ # LacusUtils.describe_type(42) # => 'integer number'
16
+ # LacusUtils.describe_type(3.14) # => 'float number'
17
+ # LacusUtils.describe_type(Float::NAN) # => 'NaN'
18
+ # LacusUtils.describe_type(Float::INFINITY) # => 'Infinity'
19
+ # LacusUtils.describe_type([]) # => 'Array (empty)'
20
+ # LacusUtils.describe_type([1, 2, 3]) # => 'number[]'
21
+ # LacusUtils.describe_type([1, 'a', 2]) # => '(number | string)[]'
22
+ # LacusUtils.describe_type({}) # => 'hash'
23
+ def self.describe_type(value)
24
+ return describe_type_array(value) if value.is_a?(Array)
25
+
26
+ describe_type_scalar(value)
27
+ end
28
+
29
+ def self.describe_type_scalar(value)
30
+ return 'nil' if value.nil?
31
+ return 'boolean' if [true, false].include?(value)
32
+
33
+ describe_type_numeric(value) || describe_type_named(value)
34
+ end
35
+ private_class_method :describe_type_scalar
36
+
37
+ def self.describe_type_numeric(value)
38
+ case value
39
+ when Integer then 'integer number'
40
+ when Float then describe_type_float(value, 'float number')
41
+ when Complex then 'complex number'
42
+ when Rational then 'rational number'
43
+ end
44
+ end
45
+ private_class_method :describe_type_numeric
46
+
47
+ def self.describe_type_named(value)
48
+ case value
49
+ when String then 'string'
50
+ when Symbol then 'symbol'
51
+ when Hash then 'hash'
52
+ when Set then 'set'
53
+ else describe_type_callable(value)
54
+ end
55
+ end
56
+ private_class_method :describe_type_named
57
+
58
+ def self.describe_type_callable(value)
59
+ case value
60
+ when Proc, Method then 'function'
61
+ when Module then 'class'
62
+ else 'object'
63
+ end
64
+ end
65
+ private_class_method :describe_type_callable
66
+
67
+ def self.describe_type_float(value, finite_label)
68
+ return 'NaN' if value.nan?
69
+ return 'Infinity' if value.infinite?
70
+
71
+ finite_label
72
+ end
73
+ private_class_method :describe_type_float
74
+
75
+ def self.describe_type_array(array)
76
+ return 'Array (empty)' if array.empty?
77
+
78
+ types = array.map { |item| describe_type_item(item) }.uniq
79
+
80
+ return "#{types.first}[]" if types.length == 1
81
+
82
+ "(#{types.join(' | ')})[]"
83
+ end
84
+ private_class_method :describe_type_array
85
+
86
+ def self.describe_type_item(item)
87
+ case item
88
+ when nil then 'nil'
89
+ when true, false then 'boolean'
90
+ when Integer then 'number'
91
+ when Float then describe_type_float(item, 'number')
92
+ when String then 'string'
93
+ else describe_type(item)
94
+ end
95
+ end
96
+ private_class_method :describe_type_item
97
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'securerandom'
4
+
5
+ module LacusUtils
6
+ NUMERIC_CHARACTERS = '0123456789'
7
+ ALPHABETIC_CHARACTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
8
+ ALPHANUMERIC_CHARACTERS = (NUMERIC_CHARACTERS + ALPHABETIC_CHARACTERS).freeze
9
+
10
+ SEQUENCE_CHARACTER_SETS = {
11
+ numeric: NUMERIC_CHARACTERS,
12
+ alphabetic: ALPHABETIC_CHARACTERS,
13
+ alphanumeric: ALPHANUMERIC_CHARACTERS
14
+ }.freeze
15
+
16
+ # Generates a random character sequence of the given length and type (numeric,
17
+ # alphabetic, or alphanumeric), drawn using a cryptographically secure RNG.
18
+ #
19
+ # @param size [Integer] length of the sequence
20
+ # @param type [Symbol] character set to draw from; one of +:numeric+ (+0-9+),
21
+ # +:alphabetic+ (+A-Z+), or +:alphanumeric+ (+0-9A-Z+). Defaults to
22
+ # +:alphanumeric+.
23
+ # @return [String] a random string of the requested length using uppercase
24
+ # letters and/or digits, depending on +type+
25
+ # @raise [ArgumentError] if +size+ is negative
26
+ # @raise [ArgumentError] if +type+ is not one of the known kinds
27
+ #
28
+ # @example
29
+ # LacusUtils.generate_random_sequence(10, :numeric) # => e.g. '9956000611'
30
+ # LacusUtils.generate_random_sequence(6, :alphabetic) # => e.g. 'AXQMZB'
31
+ # LacusUtils.generate_random_sequence(8, :alphanumeric) # => e.g. '8ZFB2K09'
32
+ # LacusUtils.generate_random_sequence(8) # => e.g. '8ZFB2K09' (alphanumeric)
33
+ def self.generate_random_sequence(size, type = :alphanumeric)
34
+ raise ArgumentError, "size must be non-negative, got #{size}" if size.negative?
35
+
36
+ characters = SEQUENCE_CHARACTER_SETS[type.to_sym]
37
+
38
+ raise ArgumentError, "unknown sequence type: #{type.inspect}" if characters.nil?
39
+
40
+ length = characters.length
41
+
42
+ Array.new(size) { characters[SecureRandom.random_number(length)] }.join
43
+ end
44
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LacusUtils
4
+ VERSION = '1.0.0'
5
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lacus-utils/version'
4
+ require_relative 'lacus-utils/describe_type'
5
+ require_relative 'lacus-utils/generate_random_sequence'
6
+
7
+ # General-purpose utility library: type description and random sequence
8
+ # generation. All entry points are module functions on +LacusUtils+.
9
+ module LacusUtils
10
+ end
metadata ADDED
@@ -0,0 +1,52 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lacus-utils
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Julio L. Muller
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2026-07-08 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Reusable utilities library for Lacus Solutions Ruby gems (type description,
14
+ random sequences).
15
+ email:
16
+ - juliolmuller@outlook.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - LICENSE
22
+ - README.md
23
+ - src/lacus-utils.rb
24
+ - src/lacus-utils/describe_type.rb
25
+ - src/lacus-utils/generate_random_sequence.rb
26
+ - src/lacus-utils/version.rb
27
+ homepage: https://github.com/LacusSolutions/br-utils-ruby
28
+ licenses:
29
+ - MIT
30
+ metadata:
31
+ source_code_uri: https://github.com/LacusSolutions/br-utils-ruby
32
+ rubygems_mfa_required: 'true'
33
+ post_install_message:
34
+ rdoc_options: []
35
+ require_paths:
36
+ - src
37
+ required_ruby_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '3.2'
42
+ required_rubygems_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ requirements: []
48
+ rubygems_version: 3.4.19
49
+ signing_key:
50
+ specification_version: 4
51
+ summary: Reusable utilities for Lacus Solutions Ruby packages
52
+ test_files: []