class VGen::StringGen

Attributes

char_gen[R]

Public Class Methods

new( char_gen: LetterGen.new, length: (4..9), except: [] ) click to toggle source
# File lib/v_gen/string_gen.rb, line 6
def initialize(
      char_gen: LetterGen.new,
      length: (4..9),
      except: []
    )
  @length = length
  @char_gen = char_gen
  @except = except
end

Public Instance Methods

call() click to toggle source
# File lib/v_gen/string_gen.rb, line 16
def call()
  
  loop do
    word = Array.new(
      word_length,
      @char_gen
    ).map(&:call).join
    return word unless @except.include? word
  end
end

Private Instance Methods

word_length() click to toggle source
# File lib/v_gen/string_gen.rb, line 29
def word_length
  length = Random.new.rand(@length) if @length.is_a? Range
  length = @length if @length.is_a? Integer
  length
end