Module: TokenChecksum::Base62
- Defined in:
- lib/token_checksum/base_62.rb
Constant Summary collapse
- PRIMITIVES =
["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"] + \ ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"] + \ ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
- PRIMITIVES_SIZE =
62
Class Method Summary collapse
Class Method Details
.encode(int, min_length: 0) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/token_checksum/base_62.rb', line 11 def encode(int, min_length: 0) return "".rjust(min_length, PRIMITIVES[0]) if int <= 0 result = "" while int > 0 result = PRIMITIVES[int % PRIMITIVES_SIZE] + result int /= PRIMITIVES_SIZE end result.rjust(min_length, PRIMITIVES[0]) end |