Class: UUID4::Formatter::URN

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

Constant Summary collapse

REGEXP =
/^urn:uuid:[\da-f]{8}-[\da-f]{4}-?[1-8][\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12}$/i.freeze
FORMAT =
'urn:uuid:%08x-%04x-%04x-%04x-%012x'

Instance Method Summary collapse

Instance Method Details

#decode(value) ⇒ Object



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

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

  value[9..].tr('-', '').hex
end

#encode(uuid) ⇒ Object



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

def encode(uuid)
  FORMAT % uuid.components
end