Class: Cql::Uuid
- Inherits:
-
Object
- Object
- Cql::Uuid
- Defined in:
- lib/cql/uuid.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 TimeUuid::Generator.
Direct Known Subclasses
Instance Method Summary collapse
- #hash ⇒ Object
-
#initialize(n) ⇒ Uuid
constructor
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.
-
#to_s ⇒ Object
Returns a string representation of this UUID in the standard 8-4-4-4-12 form.
-
#value ⇒ Bignum
(also: #to_i)
Returns the numerical representation of this UUID.
Constructor Details
#initialize(n) ⇒ 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.
18 19 20 21 22 23 24 25 |
# File 'lib/cql/uuid.rb', line 18 def initialize(n) case n when String @n = from_s(n) else @n = n end end |
Instance Method Details
#hash ⇒ Object
40 41 42 |
# File 'lib/cql/uuid.rb', line 40 def hash @n.hash end |
#to_s ⇒ Object
Returns a string representation of this UUID in the standard 8-4-4-4-12 form.
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/cql/uuid.rb', line 29 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 |
#value ⇒ Bignum Also known as: to_i
Returns the numerical representation of this UUID
48 49 50 |
# File 'lib/cql/uuid.rb', line 48 def value @n end |