Module: LSUUID
- Defined in:
- lib/lsuuid.rb,
lib/lsuuid/version.rb
Overview
:nodoc:
Constant Summary collapse
- PREFIX_LEN =
6
- PAD_CHAR =
'0'
- FLOOR_CHAR =
'0'
- CEIL_CHAR =
'f'
- DEFAULT_RAND_LEN =
16
- VERSION =
'0.1.0'
Class Method Summary collapse
-
.generate(prefix: nil, time: Time.now, mode: :random) ⇒ Object
We allow 6 chars (24 bits) of UUID to be customizable as per requirement.
Class Method Details
.generate(prefix: nil, time: Time.now, mode: :random) ⇒ Object
We allow 6 chars (24 bits) of UUID to be customizable as per requirement.
20 21 22 23 24 25 26 |
# File 'lib/lsuuid.rb', line 20 def generate(prefix: nil, time: Time.now, mode: :random) prefix_hex = validate_prefix_and_get_hex(prefix) result = prefix_hex + time.to_i.to_s(16).rjust(8, PAD_CHAR) + time.nsec.to_s(16).rjust(8, PAD_CHAR) + random_hex(prefix_hex, mode) [result[0..7], result[8..11], result[12..15], result[16..19], result[20..31]].join('-') end |