Class: UUID4::Formatter::Base62

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

Constant Summary collapse

REGEXP =
/\A[0-9A-Za-z]{14,22}\z/.freeze

Instance Method Summary collapse

Instance Method Details

#decode(value) ⇒ Object



14
15
16
17
18
19
# File 'lib/uuid4/formatter/base62.rb', line 14

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

  int
end

#encode(uuid) ⇒ Object



10
11
12
# File 'lib/uuid4/formatter/base62.rb', line 10

def encode(uuid)
  ::Base62.encode(uuid.to_i)
end