class Cassandra::Uuid

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 {Cassandra::Uuid::Generator}.

Constants

EMPTY_STRING

@private

HEX_RE

@private

HYPHEN

@private

RAW_FORMAT

@private

Public Class Methods

new(uuid) click to toggle source

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.

@param uuid [String] a 32 char uuid

@raise [ArgumentError] if the string does not conform to the expected format

   # File lib/cassandra/uuid.rb
42 def initialize(uuid)
43   @n = case uuid
44        when String
45          from_s(uuid)
46        else
47          uuid
48        end
49 end

Public Instance Methods

==(other)
Alias for: eql?
eql?(other) click to toggle source

@private

   # File lib/cassandra/uuid.rb
83 def eql?(other)
84   other.respond_to?(:value) && value == other.value
85 end
Also aliased as: ==
from_s(str) click to toggle source

See github.com/jruby/jruby/issues/1608 @private

   # File lib/cassandra/uuid.rb
93 def from_s(str)
94   str = str.gsub(HYPHEN, EMPTY_STRING)
95   raise ::ArgumentError, "Expected 32 hexadecimal digits but got #{str.length}" unless str.length == 32
96   raise ::ArgumentError, "invalid value for Integer(): \"#{str}\"" unless str =~ HEX_RE
97   Integer(str, 16)
98 end
hash() click to toggle source

@private

   # File lib/cassandra/uuid.rb
65 def hash
66   @h ||= begin
67     h = 17
68     h = 31 * h + @n.hash
69     h
70   end
71 end
to_i()
Alias for: value
to_s() click to toggle source

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

   # File lib/cassandra/uuid.rb
53 def to_s
54   @s ||= begin
55     s = RAW_FORMAT % @n
56     s.insert(20, HYPHEN)
57     s.insert(16, HYPHEN)
58     s.insert(12, HYPHEN)
59     s.insert(8, HYPHEN)
60     s
61   end
62 end
value() click to toggle source

Returns the numerical representation of this UUID

@return [Bignum] the 128 bit numerical representation

   # File lib/cassandra/uuid.rb
77 def value
78   @n
79 end
Also aliased as: to_i