Class: UUIDv6::Sequence

Inherits:
Object
  • Object
show all
Defined in:
lib/uuid_v6/sequence.rb

Overview

Usage:

seq = UUIDv6::Sequence.new
uid = seq.call
=> "137ab4b3-3748-6090-80e3-0c859007c113"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSequence

Returns a new instance of Sequence.



13
14
15
# File 'lib/uuid_v6/sequence.rb', line 13

def initialize
  @uuid_v1 = ::UUID.new
end

Instance Attribute Details

#uuid_v1Object (readonly)

Returns the value of attribute uuid_v1.



11
12
13
# File 'lib/uuid_v6/sequence.rb', line 11

def uuid_v1
  @uuid_v1
end

Instance Method Details

#call(uuid = uuid_v1.generate) ⇒ Object

Parameters:



18
19
20
21
22
23
24
25
26
27
# File 'lib/uuid_v6/sequence.rb', line 18

def call(uuid = uuid_v1.generate)
  uh = uuid.tr('-', '')
  tlo1 = uh[0...5]
  tlo2 = uh[5...8]
  tmid = uh[8...12]
  thig = uh[13...16]
  rest = uh[16..-1]
  uh6 = thig + tmid + tlo1 + '6' + tlo2 + rest
  to_uuid(uh6)
end