lib/codebreaker_kirill/validations.rb in codebreaker_kirill-1.1.1 vs lib/codebreaker_kirill/validations.rb in codebreaker_kirill-1.2.1
- old
+ new
@@ -1,23 +1,25 @@
# frozen_string_literal: true
+require_relative 'autoload'
+
class Validations
def self.validate_name(name)
raise "Name shouldn't be empty" if name.empty?
raise 'Name should be string' if name.class != String
- raise 'Name should be at least 3 characters long' if name.length < 3
- raise "Name shouldn't be more than 20 characters long" if name.length > 20
+ raise 'Name should be at least 3 characters long' if name.length < Settings::NAME_MIN_LENGTH
+ raise "Name shouldn't be more than 20 characters long" if name.length > Settings::NAME_MAX_LENGTH
end
def self.validate_guess(guess)
raise "Guess shouldn't be empty" if guess.empty?
- raise 'Guess should be at least 3 characters long' if guess.length < 4
- raise 'Guess shouldn\'t be more than 4 characters long' if guess.length > 4
+ raise "Guess should be 4 characters. Got #{guess}" if guess.length < Settings::GUESS_LENGTH
+ raise 'Guess shouldn\'t be more than 4 characters long' if guess.length > Settings::GUESS_LENGTH
end
def self.validate_difficulty(difficulty)
raise "Input shouldn't be empty" if difficulty.empty?
return if Settings::DIFFICULTY.keys.include?(difficulty)
- raise 'You should enter one of the following options: easy, medium, hell'
+ raise "You should enter one of the following options: #{Settings::DIFFICULTY.keys.join(', ')}"
end
end