Class: Cassandra::Uuid

Inherits:
Object
  • Object
show all
Defined in:
lib/cassandra/uuid.rb,
lib/cassandra/uuid/generator.rb

Overview

Represents a UUID value.

This is a very basic implementation of UUIDs and exists more or less just to encode and decode UUIDs from and to Cassandra.

If you want to generate UUIDs see Generator.

Direct Known Subclasses

TimeUuid

Defined Under Namespace

Classes: Generator

Instance Method Summary collapse

Constructor Details

#initialize(uuid) ⇒ Uuid

Creates a new UUID either from a string (expected to be on the standard 8-4-4-4-12 form, or just 32 characters without hyphens), or from a 128 bit number.

Parameters:

  • uuid (String)

    a 32 char uuid

Raises:

  • (ArgumentError)

    if the string does not conform to the expected format



42
43
44
45
46
47
48
49
# File 'lib/cassandra/uuid.rb', line 42

def initialize(uuid)
  @n = case uuid
       when String
         from_s(uuid)
       else
         uuid
       end
end

Instance Method Details

#to_sObject

Returns a string representation of this UUID in the standard 8-4-4-4-12 form.



53
54
55
56
57
58
59
60
61
62
# File 'lib/cassandra/uuid.rb', line 53

def to_s
  @s ||= begin
    s = RAW_FORMAT % @n
    s.insert(20, HYPHEN)
    s.insert(16, HYPHEN)
    s.insert(12, HYPHEN)
    s.insert(8, HYPHEN)
    s
  end
end

#valueBignum Also known as: to_i

Returns the numerical representation of this UUID

Returns:

  • (Bignum)

    the 128 bit numerical representation



77
78
79
# File 'lib/cassandra/uuid.rb', line 77

def value
  @n
end