Sha256: f6da83660645e1db1740cdbe7d0c9113141bcf08e538f64439f468a2d75f3ca7
Contents?: true
Size: 532 Bytes
Versions: 18
Compression:
Stored size: 532 Bytes
Contents
module Firefly class Base62 CHARS = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".split('') BASE = 62 def self.encode(value) s = [] while value >= BASE value, rem = value.divmod(BASE) s << CHARS[rem] end s << CHARS[value] s.reverse.join("") end def self.decode(str) str = str.split('').reverse total = 0 str.each_with_index do |v,k| total += (CHARS.index(v) * (BASE ** k)) end total end end end
Version data entries
18 entries across 18 versions & 1 rubygems