Class: UUID4::Formatter::Compact

Inherits:
Object
  • Object
show all
Defined in:
lib/uuid4/formatter/compact.rb

Constant Summary collapse

REGEXP =
/^[\da-f]{12}[1-8][\da-f]{3}[89ab][\da-f]{15}$/i.freeze
FORMAT =
'%032x'

Instance Method Summary collapse

Instance Method Details

#decode(value) ⇒ Object



13
14
15
16
17
# File 'lib/uuid4/formatter/compact.rb', line 13

def decode(value)
  return unless value.respond_to?(:to_str) && (value = value.to_str) =~ REGEXP

  value.hex
end

#encode(uuid) ⇒ Object



9
10
11
# File 'lib/uuid4/formatter/compact.rb', line 9

def encode(uuid)
  FORMAT % uuid.to_int
end