Class: VGen::VarWordGen

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

Instance Method Summary collapse

Constructor Details

#initialize(letter_gen: TypicalLetterGen.new, length: nil, size: (4..9), except: []) ⇒ VarWordGen

Returns a new instance of VarWordGen.



5
6
7
8
9
10
11
12
13
14
# File 'lib/v_gen/var_word_gen.rb', line 5

def initialize(
      letter_gen: TypicalLetterGen.new,
      length: nil,
      size: (4..9),
      except: []
    )
  @length = length || size
  @letter_gen = letter_gen
  @except = except
end

Instance Method Details

#callObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/v_gen/var_word_gen.rb', line 16

def call()
  
  loop do
    word = Array.new(
      word_length,
      @letter_gen
    ).map(&:call).join
    if word.size > 2
      if Random.new.rand(1..100) < 15
        word[Random.new.rand(1..word.size - 2)] = "_"
      end
    end
    return word unless @except.include? word
  end
end