Class: VGen::StringGen

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(char_gen: LetterGen.new, length: (4..9), except: []) ⇒ StringGen

Returns a new instance of StringGen.



6
7
8
9
10
11
12
13
14
# 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

Instance Attribute Details

#char_genObject (readonly)

Returns the value of attribute char_gen.



5
6
7
# File 'lib/v_gen/string_gen.rb', line 5

def char_gen
  @char_gen
end

Instance Method Details

#callObject



16
17
18
19
20
21
22
23
24
25
# 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