Module: Codebreaker::Validation

Included in:
Game, User
Defined in:
lib/codebreaker/validation/validation.rb

Constant Summary collapse

NUMBERS =
/^[1-6]{4}$/

Instance Method Summary collapse

Instance Method Details

#validate_guess(code) ⇒ Object

Raises:



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

def validate_guess(code)
  raise InputError unless  NUMBERS.match?(code)
end

#validate_name(name) ⇒ Object

Raises:



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

def validate_name(name)
  raise LengthError unless Constants::NAME_LENGTH.cover?(name.length)
end

#validate_state(state, current_state) ⇒ Object

Raises:



15
16
17
# File 'lib/codebreaker/validation/validation.rb', line 15

def validate_state(state, current_state)
  raise StateError unless state == current_state
end