Sha256: ada7713e79e34c172c8a40441c2dd159f600776af4316400396a24a6cea1660a

Contents?: true

Size: 697 Bytes

Versions: 6

Compression:

Stored size: 697 Bytes

Contents

require_relative "./letter_gen"

module VGen
  class StringGen
    attr_reader :char_gen
    def initialize(
          char_gen: LetterGen.new,
          length: (4..9),
          except: []
        )
      @length = length
      @char_gen = char_gen
      @except = except
    end

    def call()
      
      loop do
        word = Array.new(
          word_length,
          @char_gen
        ).map(&:call).join
        return word unless @except.include? word
      end
    end
    
    private

    def word_length
      length = Random.new.rand(@length) if @length.is_a? Range
      length = @length if @length.is_a? Integer
      length
    end
  end
end

Version data entries

6 entries across 4 versions & 2 rubygems

Version Path
bsielski_control_flow-1.0.0 vendor/bundle/ruby/2.5.0/gems/bsielski_value_generator-1.2.0/lib/bsielski_v_gen/string_gen.rb
bsielski_control_flow-1.0.0 vendor/bundle/ruby/2.5.0/gems/bsielski_value_generator-1.3.0/lib/v_gen/string_gen.rb
bsielski_control_flow-1.0.0 vendor/bundle/ruby/2.5.0/gems/bsielski_value_generator-1.4.0/lib/v_gen/string_gen.rb
bsielski_value_generator-1.4.0 lib/v_gen/string_gen.rb
bsielski_value_generator-1.3.0 lib/v_gen/string_gen.rb
bsielski_value_generator-1.2.0 lib/bsielski_v_gen/string_gen.rb