Class: Brutalitops

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

Instance Method Summary collapse

Constructor Details

#initialize(min, max, options = []) ⇒ Brutalitops

Returns a new instance of Brutalitops.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# 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

Instance Method Details



34
35
36
37
38
# File 'lib/brutalitops.rb', line 34

def print_permutations_to_console(verbose=true)
    generate_permutations(verbose).each do |permutation|
        puts permutation
    end
end


40
41
42
43
44
45
46
47
48
# File 'lib/brutalitops.rb', line 40

def print_permutations_to_csv(verbose=true)
    puts "Generating csv..." if verbose
    File.open("brutalitops_#{Time.now.strftime("%Y_%m_%d_%H%M%S").to_s}.csv", "w") do |file|
        generate_permutations(verbose).each do |permutation|
            file.puts permutation
        end
    end
    puts "Finished generating csv." if verbose
end

#to_arrayObject



50
51
52
# File 'lib/brutalitops.rb', line 50

def to_array
    generate_permutations
end