mbrcode 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/.idea/.gitignore +8 -0
- data/.idea/inspectionProfiles/Project_Default.xml +9 -0
- data/.idea/mbrcode.iml +55 -0
- data/.idea/misc.xml +4 -0
- data/.idea/modules.xml +8 -0
- data/.idea/vcs.xml +6 -0
- data/.rspec +1 -0
- data/LICENSE.txt +21 -0
- data/README.md +35 -0
- data/Rakefile +4 -0
- data/lib/mbrcode/version.rb +5 -0
- data/lib/mbrcode.rb +79 -0
- data/sig/mbrcode.rbs +4 -0
- metadata +73 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 668e1477aa761496dde6ffe763c7d80d7112999dec6860305b9a726705ace55f
|
|
4
|
+
data.tar.gz: b801310198256b2b07b36d38d08cfc710518a5ea0f77e828e3deb0acad9b0419
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: a3ca567c2fc23f2094ec3e759b2e8e6f126218d427e6ddbd3af8cbbdcd76ea732faca5745fce1b0fa0bc8d0c0cf7d22b5d945618a567743a9f11fc7c419756d9
|
|
7
|
+
data.tar.gz: d3d5a6dfb574cc42ad37749b80cfc4cb3367bb9c156b038867544f90b810928facbd097c5b4c5b70faacef89178f6d6fe1e736b127e19974bcbc9b068bb25a8e
|
data/.idea/.gitignore
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
<component name="InspectionProjectProfileManager">
|
|
2
|
+
<profile version="1.0">
|
|
3
|
+
<option name="myName" value="Project Default" />
|
|
4
|
+
<inspection_tool class="RailsChecklist05" enabled="false" level="WARNING" enabled_by_default="false" />
|
|
5
|
+
<inspection_tool class="RubyDeprecatedSymbol" enabled="false" level="WARNING" enabled_by_default="false">
|
|
6
|
+
<option name="showForOldProjects" value="false" />
|
|
7
|
+
</inspection_tool>
|
|
8
|
+
</profile>
|
|
9
|
+
</component>
|
data/.idea/mbrcode.iml
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
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="inheritedJdk" />
|
|
13
|
+
<orderEntry type="sourceFolder" forTests="false" />
|
|
14
|
+
<orderEntry type="library" scope="PROVIDED" name="bundler (v2.5.18, RVM: ruby-3.0.3 [jarvis]) [gem]" level="application" />
|
|
15
|
+
<orderEntry type="library" scope="PROVIDED" name="diff-lcs (v1.6.2, RVM: ruby-3.0.3 [jarvis]) [gem]" level="application" />
|
|
16
|
+
<orderEntry type="library" scope="PROVIDED" name="rake (v13.0.3, RVM: ruby-3.0.3 [jarvis]) [gem]" level="application" />
|
|
17
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec (v3.13.2, RVM: ruby-3.0.3 [jarvis]) [gem]" level="application" />
|
|
18
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-core (v3.13.6, RVM: ruby-3.0.3 [jarvis]) [gem]" level="application" />
|
|
19
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-expectations (v3.13.5, RVM: ruby-3.0.3 [jarvis]) [gem]" level="application" />
|
|
20
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-mocks (v3.13.7, RVM: ruby-3.0.3 [jarvis]) [gem]" level="application" />
|
|
21
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-support (v3.13.6, RVM: ruby-3.0.3 [jarvis]) [gem]" level="application" />
|
|
22
|
+
</component>
|
|
23
|
+
<component name="RakeTasksCache-v2">
|
|
24
|
+
<option name="myRootTask">
|
|
25
|
+
<RakeTaskImpl id="rake">
|
|
26
|
+
<subtasks>
|
|
27
|
+
<RakeTaskImpl description="Build mbrcode-0.1.0.gem into the pkg directory" fullCommand="build" id="build" />
|
|
28
|
+
<RakeTaskImpl id="build">
|
|
29
|
+
<subtasks>
|
|
30
|
+
<RakeTaskImpl description="Generate SHA512 checksum of mbrcode-0.1.0.gem into the checksums directory" fullCommand="build:checksum" id="checksum" />
|
|
31
|
+
</subtasks>
|
|
32
|
+
</RakeTaskImpl>
|
|
33
|
+
<RakeTaskImpl description="Remove any temporary products" fullCommand="clean" id="clean" />
|
|
34
|
+
<RakeTaskImpl description="Remove any generated files" fullCommand="clobber" id="clobber" />
|
|
35
|
+
<RakeTaskImpl description="Build and install mbrcode-0.1.0.gem into system gems" fullCommand="install" id="install" />
|
|
36
|
+
<RakeTaskImpl id="install">
|
|
37
|
+
<subtasks>
|
|
38
|
+
<RakeTaskImpl description="Build and install mbrcode-0.1.0.gem into system gems without network access" fullCommand="install:local" id="local" />
|
|
39
|
+
</subtasks>
|
|
40
|
+
</RakeTaskImpl>
|
|
41
|
+
<RakeTaskImpl description="Create tag v0.1.0 and build and push mbrcode-0.1.0.gem to rubygems.org" fullCommand="release[remote]" id="release[remote]" />
|
|
42
|
+
<RakeTaskImpl description="" fullCommand="default" id="default" />
|
|
43
|
+
<RakeTaskImpl description="" fullCommand="release" id="release" />
|
|
44
|
+
<RakeTaskImpl id="release">
|
|
45
|
+
<subtasks>
|
|
46
|
+
<RakeTaskImpl description="" fullCommand="release:guard_clean" id="guard_clean" />
|
|
47
|
+
<RakeTaskImpl description="" fullCommand="release:rubygem_push" id="rubygem_push" />
|
|
48
|
+
<RakeTaskImpl description="" fullCommand="release:source_control_push" id="source_control_push" />
|
|
49
|
+
</subtasks>
|
|
50
|
+
</RakeTaskImpl>
|
|
51
|
+
</subtasks>
|
|
52
|
+
</RakeTaskImpl>
|
|
53
|
+
</option>
|
|
54
|
+
</component>
|
|
55
|
+
</module>
|
data/.idea/misc.xml
ADDED
data/.idea/modules.xml
ADDED
data/.idea/vcs.xml
ADDED
data/.rspec
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
--require spec_helper
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 delacruzjames
|
|
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,35 @@
|
|
|
1
|
+
# Mbrcode
|
|
2
|
+
|
|
3
|
+
TODO: Delete this and the text below, and describe your gem
|
|
4
|
+
|
|
5
|
+
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/mbrcode`. To experiment with that code, run `bin/console` for an interactive prompt.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
|
|
10
|
+
|
|
11
|
+
Install the gem and add to the application's Gemfile by executing:
|
|
12
|
+
|
|
13
|
+
$ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
|
|
14
|
+
|
|
15
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
|
16
|
+
|
|
17
|
+
$ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
TODO: Write usage instructions here
|
|
22
|
+
|
|
23
|
+
## Development
|
|
24
|
+
|
|
25
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
26
|
+
|
|
27
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
28
|
+
|
|
29
|
+
## Contributing
|
|
30
|
+
|
|
31
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/mbrcode.
|
|
32
|
+
|
|
33
|
+
## License
|
|
34
|
+
|
|
35
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/lib/mbrcode.rb
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
require "mbrcode/version"
|
|
2
|
+
require "mutex_m"
|
|
3
|
+
|
|
4
|
+
module Mbrcode
|
|
5
|
+
extend Mutex_m
|
|
6
|
+
|
|
7
|
+
@sequence = 0
|
|
8
|
+
|
|
9
|
+
class << self
|
|
10
|
+
#
|
|
11
|
+
# New Rules:
|
|
12
|
+
# - Prefix processed to exactly 4 chars using logic described
|
|
13
|
+
# - MAX 16 digits total after prefix+shard
|
|
14
|
+
#
|
|
15
|
+
def generate(prefix: "mbr", shard: 1)
|
|
16
|
+
prefix_str = normalize_prefix(prefix)
|
|
17
|
+
shard_str = shard.to_i.to_s
|
|
18
|
+
|
|
19
|
+
seq = next_sequence
|
|
20
|
+
|
|
21
|
+
# remaining characters allowed for digits
|
|
22
|
+
max_digits = 16 - (prefix_str.length + shard_str.length)
|
|
23
|
+
|
|
24
|
+
# enforce enough space for meaningful numbering
|
|
25
|
+
raise "Shard too long" if max_digits < 4
|
|
26
|
+
|
|
27
|
+
digits = format("%0#{max_digits}d", seq)
|
|
28
|
+
|
|
29
|
+
grouped =
|
|
30
|
+
if max_digits > 4
|
|
31
|
+
digits.scan(/.{1,4}/).join("-")
|
|
32
|
+
else
|
|
33
|
+
digits
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
"#{prefix_str}#{shard_str}-#{grouped}"
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
private
|
|
40
|
+
|
|
41
|
+
# -----------------------------
|
|
42
|
+
# PREFIX NORMALIZATION LOGIC
|
|
43
|
+
# -----------------------------
|
|
44
|
+
def normalize_prefix(prefix)
|
|
45
|
+
str = prefix.to_s.strip.upcase
|
|
46
|
+
|
|
47
|
+
# Multi-word? Use initials.
|
|
48
|
+
if str.include?(" ")
|
|
49
|
+
initials = str.split.map { |w| w[0] }.join
|
|
50
|
+
return pad_or_trim(initials)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# Single word:
|
|
54
|
+
if str.length < 4
|
|
55
|
+
return pad_or_trim(str)
|
|
56
|
+
else
|
|
57
|
+
# Use first 4 chars
|
|
58
|
+
return str[0, 4]
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def pad_or_trim(str)
|
|
63
|
+
if str.length >= 4
|
|
64
|
+
str[0, 4]
|
|
65
|
+
else
|
|
66
|
+
# pad numbers until length = 4
|
|
67
|
+
str.ljust(4, "0")
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def next_sequence
|
|
72
|
+
synchronize do
|
|
73
|
+
current = @sequence
|
|
74
|
+
@sequence += 1
|
|
75
|
+
current
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
data/sig/mbrcode.rbs
ADDED
metadata
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: mbrcode
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Sensei James
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2025-11-18 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: rspec
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '3.12'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '3.12'
|
|
27
|
+
description: Generates structured membership IDs like MBR1-0000-0000-0000 for apps,
|
|
28
|
+
systems, and organizations.
|
|
29
|
+
email:
|
|
30
|
+
- delacruzjamesmartin@gmail.com
|
|
31
|
+
executables: []
|
|
32
|
+
extensions: []
|
|
33
|
+
extra_rdoc_files: []
|
|
34
|
+
files:
|
|
35
|
+
- ".idea/.gitignore"
|
|
36
|
+
- ".idea/inspectionProfiles/Project_Default.xml"
|
|
37
|
+
- ".idea/mbrcode.iml"
|
|
38
|
+
- ".idea/misc.xml"
|
|
39
|
+
- ".idea/modules.xml"
|
|
40
|
+
- ".idea/vcs.xml"
|
|
41
|
+
- ".rspec"
|
|
42
|
+
- LICENSE.txt
|
|
43
|
+
- README.md
|
|
44
|
+
- Rakefile
|
|
45
|
+
- lib/mbrcode.rb
|
|
46
|
+
- lib/mbrcode/version.rb
|
|
47
|
+
- sig/mbrcode.rbs
|
|
48
|
+
homepage: https://github.com/delacruzjames/mbrcode
|
|
49
|
+
licenses:
|
|
50
|
+
- MIT
|
|
51
|
+
metadata:
|
|
52
|
+
homepage_uri: https://github.com/delacruzjames/mbrcode
|
|
53
|
+
source_code_uri: https://github.com/delacruzjames/mbrcode
|
|
54
|
+
post_install_message:
|
|
55
|
+
rdoc_options: []
|
|
56
|
+
require_paths:
|
|
57
|
+
- lib
|
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
59
|
+
requirements:
|
|
60
|
+
- - ">="
|
|
61
|
+
- !ruby/object:Gem::Version
|
|
62
|
+
version: 3.0.0
|
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
64
|
+
requirements:
|
|
65
|
+
- - ">="
|
|
66
|
+
- !ruby/object:Gem::Version
|
|
67
|
+
version: '0'
|
|
68
|
+
requirements: []
|
|
69
|
+
rubygems_version: 3.5.9
|
|
70
|
+
signing_key:
|
|
71
|
+
specification_version: 4
|
|
72
|
+
summary: Simple and clean membership code generator.
|
|
73
|
+
test_files: []
|