Class: 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.



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

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

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



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

def errors
  @errors
end

#numberObject

Returns the value of attribute number.



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

def number
  @number
end

Instance Method Details

#validateObject



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

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