class Shufflino::Core
Public Class Methods
new(seeds)
click to toggle source
# File lib/shufflino.rb, line 10 def initialize(seeds) if seeds.first.is_a? Array @seeds = seeds elsif seeds.first.is_a? String @seeds = seeds.map {|s| s.split("") } end raise "Empty seeds array" if seeds.empty? end
Public Instance Methods
alphabet_size()
click to toggle source
# File lib/shufflino.rb, line 43 def alphabet_size @seeds.first.size end
combinations_size()
click to toggle source
# File lib/shufflino.rb, line 39 def combinations_size alphabet_size ** id_length end
generate(id)
click to toggle source
# File lib/shufflino.rb, line 21 def generate(id) id = id.to_i raise Shufflino::Error.new 'Not enough seeds!' if id > combinations_size - 1 indices = Bases[id.to_s].in_base(10).to_base(alphabet_size, array: true).map(&:to_i) indices = Array.new(id_length - indices.size, 0) + indices # rjust result = "" indices.each_with_index do |index, i| alphabet = @seeds[i] result << alphabet[index].to_s end result end
id_length()
click to toggle source
# File lib/shufflino.rb, line 47 def id_length @seeds.size end