Class: Rubeyond::UUID
- Inherits:
-
Object
- Object
- Rubeyond::UUID
- Includes:
- Comparable
- Defined in:
- lib/rubeyond/uuid.rb
Overview
The UUID
class handles representing a universally unique identifier.
Examples
# Create a new unique UUID.
@uuid = Rubeyond::UUID.create
# Create an instance of UUID from a uuid value.
@uuid = Rubeyond::UUID.create :uuid => "fd0289a5-8eec-4a08-9283-81d02c9d2fff"
# Create an instance of UUID from an encoded value.
@uuid = Rubeyond::UUID.create :encoded => 336307859334295828133695192821923655679
Instance Attribute Summary collapse
-
#encoded ⇒ Object
readonly
The encoded value of the
UUID
. -
#uuid ⇒ Object
readonly
A string representation of the
UUID
.
Class Method Summary collapse
-
.create(options = {}) ⇒ Object
Creates a new
UUID
instance.
Instance Method Summary collapse
-
#<=>(that) ⇒ Object
Spaceship operator.
-
#==(that) ⇒ Object
Comparison operator.
-
#to_s ⇒ Object
Returns a string representation of the UUID.
Instance Attribute Details
#encoded ⇒ Object (readonly)
The encoded value of the UUID
.
39 40 41 |
# File 'lib/rubeyond/uuid.rb', line 39 def encoded @encoded end |
#uuid ⇒ Object (readonly)
A string representation of the UUID
.
36 37 38 |
# File 'lib/rubeyond/uuid.rb', line 36 def uuid @uuid end |
Class Method Details
.create(options = {}) ⇒ Object
Creates a new UUID
instance.
If provided, it will create a new instances with the given uuid value.
Attributes
-
options
- creation options
Options
-
+:uuid: - the
UUID
value to use -
+:encoded: - an encoded
UUID
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/rubeyond/uuid.rb', line 55 def self.create( = {}) # if we have a uuid then create from that if [:uuid] Rubeyond::UUID.new([:uuid]) elsif [:encoded] uuid = decode([:encoded]) Rubeyond::UUID.new(uuid) else Rubeyond::UUID.new end end |
Instance Method Details
#<=>(that) ⇒ Object
Spaceship operator.
73 74 75 76 77 78 79 80 81 |
# File 'lib/rubeyond/uuid.rb', line 73 def <=>(that) # :nodoc: if self.uuid < that.uuid -1 elsif self.uuid > that.uuid 1 else 0 end end |
#==(that) ⇒ Object
Comparison operator.
68 69 70 |
# File 'lib/rubeyond/uuid.rb', line 68 def ==(that) # :nodoc: self.uuid == that.uuid end |
#to_s ⇒ Object
Returns a string representation of the UUID.
84 85 86 |
# File 'lib/rubeyond/uuid.rb', line 84 def to_s @uuid end |