Method: EncodeId#encode

Defined in:
lib/encode_id.rb

#encode(id) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/encode_id.rb', line 25

def encode(id)
  if(!@grows && id > max = self.max_id())
    raise "Limit id(#{id}) for #{@max_digits} digits(#{max}) in EncodeId.encode, possible lost of information"
  end
  ret = ''
  aux = id
  bit = 0
  while (@grows && aux) || (@max_digits > bit) do
    a = aux % @n_base
    ret.concat(@base[bit % @base_len][a])
    aux = (aux - a) / @n_base
    bit += 1
  end
  return ret
end