class Girbot::StringGenerator

Attributes

items[RW]

Public Class Methods

new() click to toggle source
# File lib/girbot/string_generator.rb, line 5
def initialize
  @items = ('!'..'~').to_a
end

Public Instance Methods

items=(items) click to toggle source
# File lib/girbot/string_generator.rb, line 9
def items= items
  @items = items
end
repeated_permutation(min_length=nil, max_length=nil) click to toggle source
# File lib/girbot/string_generator.rb, line 13
def repeated_permutation min_length=nil, max_length=nil
  items = []
  min_length = 1 if min_length.nil?
  max_length = @items.size if max_length.nil?
  raise 'min is greater than max' if min_length > max_length

  (min_length..max_length).each do |range|
    items.concat repeated_permutation_with_length(range)
  end

  items
end
repeated_permutation_with_length(length) click to toggle source
# File lib/girbot/string_generator.rb, line 26
def repeated_permutation_with_length length
  stringify @items.repeated_permutation(length).to_a
end
stringify(array) click to toggle source
# File lib/girbot/string_generator.rb, line 30
def stringify array
  array.map { |e| e.join('') }.uniq.reject { |c| c.empty? }
end