Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/userify/uid.rb

Constant Summary collapse

BASE62_PRIMITIVES =
{}.tap do |h|
  (('0'..'9').to_a + ('A'..'Z').to_a + ('a'..'z').to_a).each_with_index {|e, i| h[e] = i }
end

Instance Method Summary collapse

Instance Method Details

#base62Object



46
47
48
49
50
51
52
53
54
55
# File 'lib/userify/uid.rb', line 46

def base62
  i = 0
  i_out = 0
  self.split(//).reverse.each do |c|
    place = BASE62_PRIMITIVES.size ** i
    i_out += BASE62_PRIMITIVES[c] * place
    i += 1
  end
  i_out
end