class Brutalitops

Public Class Methods

new(min, max, options=[]) click to toggle source
# File lib/brutalitops.rb, line 5
def initialize(min, max, options=[])
    alphabet_lowercase = ('a'..'z').to_a
    alphabet_uppercase = ('A'..'Z').to_a
    nums = (0..9).to_a
    specials = [' ', '!', '@', '#', '$', '%','^', '&', '*', '(', ')', '-', '_', '+', '=', '[', ']', '{', '}', '|', '\\', '?', "/", '<', '>', '.', ',', '~', '`']

    @min = min
    @max = max
    @selection = []

    if !options.empty?
        options.each do |option|
            case option
            when :alpha_lowercase
                @selection += alphabet_lowercase
            when :alpha_uppercase
                @selection += alphabet_uppercase
            when :nums
                @selection += nums
            when :special_chars
                @selection += specials
            else
                #handle custom array passed in
                @selection += option
            end
        end
    end
end

Public Instance Methods

print_permutations_to_console(verbose=true) click to toggle source
print_permutations_to_csv(verbose=true) click to toggle source
to_array() click to toggle source
# File lib/brutalitops.rb, line 50
def to_array
    generate_permutations
end

Private Instance Methods

generate_permutations(verbose=false) click to toggle source
# File lib/brutalitops.rb, line 56
def generate_permutations(verbose=false)
    permutations = []
    puts "Generating permutations..." if verbose

    @min.upto(@max) do |i|
        puts "Building permutation with #{i} choices. This might take some time." if verbose
        temp_arr = @selection.repeated_permutation(i).to_a
        temp_arr.each {|t| permutations << t.join.to_s}
        puts "Finished building permutation with #{i} choices." if verbose
    end

    puts "Finished permutations." if verbose
    puts "Number of permutations generated: #{permutations.size}" if verbose

    permutations
end