class StatelyDB::UUID

encoding.
Internally this class uses the byte_string attribute to store the UUID as a string with the Encoding::ASCII_8BIT
and this class provides convenience methods for converting to the base16 representation specified in RFC 9562.
UUID is a helper class for working with UUIDs in StatelyDB. The ruby version of a StatelyDB is a binary string,

def self.parse(byte_string)

Returns:
  • (StatelyDB::UUID) -

Parameters:
  • byte_string (String) -- A binary-encoded string (eg: Encoding::ASCII_8BIT encoding) that is 16 bytes in length, or a
def self.parse(byte_string)
  return byte_string if byte_string.is_a?(StatelyDB::UUID)
  if valid_uuid?(byte_string)
    return new(byte_string)
  elsif byte_string.match(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i)
    return new([byte_string.delete("-")].pack("H*"))
  end
  raise "Invalid UUID"
end

def self.valid_uuid?(byte_string)

Returns:
  • (Boolean) -

Parameters:
  • byte_string (String) -- A binary-encoded string (eg: Encoding::ASCII_8BIT encoding)
def self.valid_uuid?(byte_string)
  byte_string.encoding == Encoding::BINARY && byte_string.bytesize == 16
end

def <=>(other)

Returns:
  • (Integer) -

Parameters:
  • other (StatelyDB::UUID) --
def <=>(other)
  to_s <=> other.to_s
end

def ==(other)

Returns:
  • (Boolean) -

Parameters:
  • other (StatelyDB::UUID) --
def ==(other)
  self.class == other.class &&
    @byte_string == other.byte_string
end

def empty?

Returns:
  • (Boolean) -
def empty?
  @byte_string.empty?
end

def initialize(byte_string)

Parameters:
  • byte_string (String) -- A binary-encoded string (eg: Encoding::ASCII_8BIT encoding)
def initialize(byte_string)
  @byte_string = byte_string
end

def to_base64

Returns:
  • (String) -
def to_base64
  [@byte_string].pack("m0").tr("=", "").tr("+/", "-_")
end

def to_s

Returns:
  • (String) -
def to_s
  to_str
end

def to_str

Returns:
  • (String) -
def to_str
  @byte_string.unpack("H8H4H4H4H12").join("-")
end