Sha256: 0fe4cbe46acff173fc3b09d6e41083ea31fa040ec0524673c1ec5c52ed3173a2
Contents?: true
Size: 547 Bytes
Versions: 34
Compression:
Stored size: 547 Bytes
Contents
# encoding: UTF-8 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
34 entries across 34 versions & 4 rubygems