Class: Codebreaker::Difficulty

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

Constant Summary collapse

LEVELS =
{
  easy: { attempts: 15, hints: 3, name: 'easy', id: 1 },
  medium: { attempts: 10, hints: 2, name: 'medium', id: 2 },
  hell: { attempts: 5, hints: 1, name: 'hell', id: 3 }
}.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(level = :easy) ⇒ Difficulty

Returns a new instance of Difficulty.



13
14
15
16
# File 'lib/entities/difficulty.rb', line 13

def initialize(level = :easy)
  @level = LEVELS[level.to_sym]
  @errors = []
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



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

def errors
  @errors
end

#levelObject (readonly)

Returns the value of attribute level.



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

def level
  @level
end

Instance Method Details

#validateObject



18
19
20
# File 'lib/entities/difficulty.rb', line 18

def validate
  @errors << 'unexpected_comand' unless LEVELS.values.include? @level
end