Class: UUID4::Formatter::Base62

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

Constant Summary collapse

REGEXP =
/^[0-9A-z]{14,22}$/i

Instance Method Summary collapse

Instance Method Details

#decode(value) ⇒ Object


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

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

#encode(uuid) ⇒ Object


8
9
10
# File 'lib/uuid4/formatter/base62.rb', line 8

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