Class: CodebreakerAp::Validator

Inherits:
Object
  • Object
show all
Includes:
Validation
Defined in:
lib/codebreaker_ap/entities/validator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Validation

#check_chars_range, #check_difficulty, #check_length

Constructor Details

#initializeValidator

Returns a new instance of Validator.



7
8
9
# File 'lib/codebreaker_ap/entities/validator.rb', line 7

def initialize
  @errors = []
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



5
6
7
# File 'lib/codebreaker_ap/entities/validator.rb', line 5

def errors
  @errors
end

Instance Method Details

#validate_difficulty(level, difficulty_keys) ⇒ Object



11
12
13
14
15
# File 'lib/codebreaker_ap/entities/validator.rb', line 11

def validate_difficulty(level, difficulty_keys)
  check_difficulty(level.to_sym, difficulty_keys)
rescue WrongDifficultyError => e
  @errors.push(e)
end

#validate_length(name, name_length) ⇒ Object



17
18
19
20
21
# File 'lib/codebreaker_ap/entities/validator.rb', line 17

def validate_length(name, name_length)
  check_length(name, name_length)
rescue WrongLengthError => e
  @errors.push(e)
end

#validate_player_answer(answer, answer_length, answer_chars_range) ⇒ Object



23
24
25
26
27
28
# File 'lib/codebreaker_ap/entities/validator.rb', line 23

def validate_player_answer(answer, answer_length, answer_chars_range)
  validate_length(answer, answer_length)
  check_chars_range(answer, answer_chars_range)
rescue WrongNumbersError => e
  @errors.push(e)
end