Project

mbrcode

0.0
The project is in a healthy, maintained state
Generates structured membership IDs like MBR1-0000-0000-0000 for apps, systems, and organizations.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

~> 3.12
 Project Readme

Mbrcode

Mbrcode is a lightweight, deterministic, and clean membership code generator for Ruby applications.

It produces stable, structured IDs using the format:

PREFIX + SHARD + "-" + DIGITS

Where:

  • PREFIX โ†’ normalized to exactly 4 characters
  • SHARD โ†’ numeric grouping/version number
  • DIGITS โ†’ auto-incrementing sequence
  • Raw length before dashes = EXACTLY 16 characters

Example output:

MBR1-0000-0000-000

Mbrcode is ideal for membership systems, gyms, schools, apps, organizations, ERPs, identity platforms, and anything requiring clean, compact, and consistent codes.


โœจ Features

  • ๐Ÿ”’ Thread-safe incremental counter
  • ๐Ÿงฉ Smart prefix normalization rules
  • ๐Ÿ“ Always 16 raw characters before dash grouping
  • ๐Ÿ”ฃ Groups digits into 4-4-4 format when possible
  • โš™๏ธ Configurable prefix and shard
  • ๐Ÿ’Ž Zero external dependencies
  • ๐Ÿš€ Fast, simple, production-ready

๐Ÿ“ฆ Installation

Add to your Gemfile:

gem "mbrcode"

Install:

bundle install

Or install manually:

gem install mbrcode

๐Ÿš€ Usage

Default generation

Mbrcode.generate
# => "MBR1-0000-0000-000"

Custom prefix

Mbrcode.generate(prefix: "user")
# => "USER1-0000-0000-000"

Multi-word prefix โ†’ initials

Mbrcode.generate(prefix: "karate membership")
# => "KM00-0000-0000-000"

Prefix shorter than 4 chars โ†’ padded

Mbrcode.generate(prefix: "ab")
# => "AB00-0000-0000-000"

Long prefix โ†’ first 4 characters

Mbrcode.generate(prefix: "customer")
# => "CUST1-0000-0000-000"

Custom shard

Mbrcode.generate(prefix: "mbr", shard: 2)
# => "MBR2-0000-0000-000"

๐Ÿง  Prefix Normalization Rules

Input Prefix Output Prefix Rule Applied
"m" "M000" padded to 4 characters
"ab" "AB00" padded to 4 characters
"karate membership" "KM00" initials + padded
"ruby on rails" "ROR0" initials + padded
"customer" "CUST" first 4 characters
"USER" "USER" unchanged (4 chars)

๐Ÿ”ข 16-Character Enforcement

Before grouping and adding dashes, the ID ALWAYS equals:

PREFIX(4) + SHARD(N) + DIGITS(M) = 16 characters

If the shard leaves no space for digits:

Mbrcode.generate(prefix: "abcd", shard: 999999999)
# => raises "Shard too long"

This ensures consistent, predictable, compact membership IDs.


๐Ÿงช Testing

Run RSpec tests:

bundle exec rspec

All tests should pass.


๐Ÿ›  Development

Clone the repository:

git clone https://github.com/delacruzjames/mbrcode.git
cd mbrcode

Install dependencies:

bundle install

Run tests:

bundle exec rspec

๐Ÿค Contributing

Pull requests are welcome!
Please include tests for new features or bug fixes.


๐Ÿ“œ License

Released under the MIT License.


๐Ÿ‘ค Author

Sensei James Dela Cruz
Ruby Developer โ€ข API Architect โ€ข Karate Instructor

๐Ÿ“ง Email: delacruzjamesmartin@gmail.com
๐Ÿ™ GitHub: @delacruzjames