Class: Codebreaker::Guess
- Inherits:
-
ValidatableEntity
- Object
- ValidatableEntity
- Codebreaker::Guess
- Defined in:
- lib/app/entities/guess.rb
Constant Summary collapse
- HINT =
'hint'
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#input ⇒ Object
readonly
Returns the value of attribute input.
Instance Method Summary collapse
- #as_array_of_numbers ⇒ Object
- #hint? ⇒ Boolean
-
#initialize(input) ⇒ Guess
constructor
A new instance of Guess.
- #validate ⇒ Object
Methods inherited from ValidatableEntity
Methods included from Validator
#check_cover?, #check_include?, #check_numbers?, #check_size?
Constructor Details
#initialize(input) ⇒ Guess
Returns a new instance of Guess.
9 10 11 12 |
# File 'lib/app/entities/guess.rb', line 9 def initialize(input) super() @input = input end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
5 6 7 |
# File 'lib/app/entities/guess.rb', line 5 def errors @errors end |
#input ⇒ Object (readonly)
Returns the value of attribute input.
5 6 7 |
# File 'lib/app/entities/guess.rb', line 5 def input @input end |
Instance Method Details
#as_array_of_numbers ⇒ Object
21 22 23 |
# File 'lib/app/entities/guess.rb', line 21 def as_array_of_numbers @as_array_of_numbers ||= @input.chars.map(&:to_i) end |
#hint? ⇒ Boolean
25 26 27 |
# File 'lib/app/entities/guess.rb', line 25 def hint? @input == HINT end |
#validate ⇒ Object
14 15 16 17 18 19 |
# File 'lib/app/entities/guess.rb', line 14 def validate return if hint? @errors << I18n.t('invalid.include_error') unless check_numbers?(@input, valid_numbers) @errors << I18n.t('invalid.size_error') unless check_size?(@input, Game::CODE_SIZE) end |