Class: StringRandomizer::StringGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/string_randomizer/string_generator.rb

Instance Method Summary collapse

Constructor Details

#initialize(allowed_char, string_lenght, total_line) ⇒ StringGenerator

Returns a new instance of StringGenerator.



2
3
4
5
6
# File 'lib/string_randomizer/string_generator.rb', line 2

def initialize(allowed_char, string_lenght, total_line)
  @allowed_char = allowed_char
  @string_lenght = string_lenght
  @total_line = total_line
end

Instance Method Details

#generate_random_char_lineObject



13
14
15
# File 'lib/string_randomizer/string_generator.rb', line 13

def generate_random_char_line
  (0...@string_lenght).map { @allowed_char[rand(@allowed_char.length)] }.join
end

#generate_stringObject



8
9
10
11
# File 'lib/string_randomizer/string_generator.rb', line 8

def generate_string
  return generate_random_char_line if @total_line == 1
  puts (1..@total_line).map{|n| generate_random_char_line}.join("\n")
end