Class: UUID4::Formatter::Default

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

Constant Summary collapse

REGEXP =
/^[\da-f]{8}-[\da-f]{4}-[1-5][\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12}$/i
FORMAT =
'%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/default.rb', line 11

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

#encode(uuid) ⇒ Object



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

def encode(uuid)
  FORMAT % uuid.components
end