Class: Codebreaker::Guess

Inherits:
BaseClass show all
Defined in:
lib/entities/guess.rb

Constant Summary collapse

VALID_GUESS_LENGTH =
4
VALID_GUESS_RANGE =
('0'..'6').freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BaseClass

#valid?

Methods included from Validator

#check_length?, #check_length_in_range?, #check_number_in_range?, #check_symbols_in_range?

Constructor Details

#initialize(guess) ⇒ Guess

Returns a new instance of Guess.



11
12
13
14
# File 'lib/entities/guess.rb', line 11

def initialize(guess)
  @number = guess
  @errors = []
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



9
10
11
# File 'lib/entities/guess.rb', line 9

def errors
  @errors
end

#numberObject

Returns the value of attribute number.



8
9
10
# File 'lib/entities/guess.rb', line 8

def number
  @number
end

Instance Method Details

#validateObject



16
17
18
19
# File 'lib/entities/guess.rb', line 16

def validate
  @errors << 'error_number_length' unless check_length?(@number, VALID_GUESS_LENGTH)
  @errors << 'error_number_digit' unless check_number_in_range?(@number, VALID_GUESS_RANGE)
end