Module: UUID7

Defined in:
lib/uuid7.rb,
lib/uuid7/version.rb,
lib/uuid7/generator.rb

Overview

UUID v7 Generator

Defined Under Namespace

Modules: Generator

Constant Summary collapse

VERSION =
"0.2.0"

Class Method Summary collapse

Class Method Details

.generate(timestamp: Process.clock_gettime(Process::CLOCK_REALTIME, :millisecond)) ⇒ String

Generate a new UUID v7

Examples:

Generate a new UUID v7 for the current timestamp

UUID7.generate

Parameters:

  • timestamp (Integer) (defaults to: Process.clock_gettime(Process::CLOCK_REALTIME, :millisecond))

    the timestamp to use for UUID v7

Returns:

  • (String)

    the generated UUID v7 string



20
21
22
# File 'lib/uuid7.rb', line 20

def self.generate(timestamp: Process.clock_gettime(Process::CLOCK_REALTIME, :millisecond))
  format("%08x-%04x-%04x-%04x-%04x%08x", *Generator.generate(timestamp))
end