Class: Tiqav::AlphaNum

Inherits:
Object
  • Object
show all
Defined in:
lib/tiqav/alpha_num.rb

Class Method Summary collapse

Class Method Details

.decode(str) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/tiqav/alpha_num.rb', line 12

def self.decode(str)
  arr = str.split('').map{|i| self.table.index i }
  for i in 0...arr.size do
    return arr[i] if i == arr.size-1
    arr[i+1] += arr[i]*62
  end
end

.encode(num) ⇒ Object



8
9
10
# File 'lib/tiqav/alpha_num.rb', line 8

def self.encode(num)
  num > 61 ? self.encode(num/62)+self.table[num%62] : self.table[num%62]
end

.tableObject



4
5
6
# File 'lib/tiqav/alpha_num.rb', line 4

def self.table
  @@table ||= '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'.split('')
end