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-5][\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12}$/i
FORMAT =
'urn:uuid:%08x-%04x-%04x-%04x-%012x'.freeze

Instance Method Summary collapse

Instance Method Details

#decode(value) ⇒ Object



11
12
13
14
15
# File 'lib/uuid4/formatter/urn.rb', line 11

def decode(value)
  if value.respond_to?(:to_str) && (value = value.to_str) =~ REGEXP
    value[9..-1].tr('-', '').hex
  end
end

#encode(uuid) ⇒ Object



7
8
9
# File 'lib/uuid4/formatter/urn.rb', line 7

def encode(uuid)
  FORMAT % uuid.components
end