class Xencoder::Xbase
Attributes
chars[R]
Public Class Methods
new(chars)
click to toggle source
# File lib/xencoder/xbase.rb, line 4 def initialize(chars) @chars = chars.dup.freeze end
Public Instance Methods
to_i(str)
click to toggle source
# File lib/xencoder/xbase.rb, line 8 def to_i(str) sum = 0 str.chars.reverse.each_with_index do |char, i| sum += chars.index(char) * chars.size**i end sum end
to_x(num)
click to toggle source
# File lib/xencoder/xbase.rb, line 16 def to_x(num) str = chars.at(num % chars.size) num /= chars.size str = "#{to_x(num)}#{str}" if num > 0 str end