Class: Codebreaker::SecretCodeGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/codebreaker/secret_code_generator.rb

Constant Summary collapse

LENGTH =
4
RANGE =
(1..6).freeze
VALID_REGEXP =
/^[#{RANGE.min}-#{RANGE.max}]{#{LENGTH}}$/.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.string_valid?(secret_code) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/codebreaker/secret_code_generator.rb', line 7

def self.string_valid?(secret_code)
  VALID_REGEXP.match?(secret_code)
end

Instance Method Details

#callObject



11
12
13
# File 'lib/codebreaker/secret_code_generator.rb', line 11

def call
  Array.new(LENGTH) { rand(RANGE) }
end