Class: GnUUID::UUID
- Inherits:
-
Object
- Object
- GnUUID::UUID
- Defined in:
- lib/gn_uuid/uuid.rb
Overview
handles UUID byte string and it’s conversion to different format NOTE: this is a general UUID class which is not limited to only v5
Instance Attribute Summary collapse
-
#bytes ⇒ Object
readonly
Returns the value of attribute bytes.
Instance Method Summary collapse
-
#initialize(bytes) ⇒ UUID
constructor
A new instance of UUID.
- #to_i ⇒ Object
- #to_s ⇒ Object
- #to_uri ⇒ Object (also: #inspect)
- #version ⇒ Object
Constructor Details
#initialize(bytes) ⇒ UUID
Returns a new instance of UUID.
9 10 11 12 |
# File 'lib/gn_uuid/uuid.rb', line 9 def initialize(bytes) @bytes = bytes @ary = @bytes.unpack("C*") end |
Instance Attribute Details
#bytes ⇒ Object (readonly)
Returns the value of attribute bytes.
7 8 9 |
# File 'lib/gn_uuid/uuid.rb', line 7 def bytes @bytes end |
Instance Method Details
#to_i ⇒ Object
21 22 23 |
# File 'lib/gn_uuid/uuid.rb', line 21 def to_i @to_i ||= @ary.inject(0) { |a, e| a << 8 | e } end |
#to_s ⇒ Object
14 15 16 17 18 19 |
# File 'lib/gn_uuid/uuid.rb', line 14 def to_s return @str if @str fmt = "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-" \ "%02x%02x%02x%02x%02x%02x" @str = fmt % @ary end |
#to_uri ⇒ Object Also known as: inspect
25 26 27 |
# File 'lib/gn_uuid/uuid.rb', line 25 def to_uri "urn:uuid:" + to_s end |
#version ⇒ Object
31 32 33 |
# File 'lib/gn_uuid/uuid.rb', line 31 def version @ary[6] >> 4 end |