Module: Kiev::Base52

Defined in:
lib/kiev/base52.rb

Constant Summary collapse

KEYS =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".freeze
BASE =
KEYS.length.freeze

Class Method Summary collapse

Class Method Details

.encode(num) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/kiev/base52.rb', line 8

def self.encode(num)
  return KEYS[0] if num == 0
  return nil if num < 0

  str = ""
  while num > 0
    str.prepend(KEYS[num % BASE])
    num /= BASE
  end
  str
end