lib/console_app/difficult.rb in codebreaker_dmitriev-0.1.0 vs lib/console_app/difficult.rb in codebreaker_dmitriev-0.2.0
- old
+ new
@@ -1,33 +1,21 @@
-require_relative './errors/errors'
-
class Difficult
- include Errors
-
- DIFFICULTS = {
- easy: 'easy',
- medium: 'medium',
- hell: 'hell'
- }.freeze
-
attr_reader :level
def initialize(level)
- raise WrongDifficultError unless valid? level
-
@level = level.downcase
end
def to_i
- case @level.downcase
- when DIFFICULTS[:hell] then 1
- when DIFFICULTS[:medium] then 2
- when DIFFICULTS[:easy] then 3
+ case @level
+ when name('hell') then 1
+ when name('medium') then 2
+ when name('easy') then 3
end
end
private
- def valid?(level)
- level.is_a?(String) && DIFFICULTS.values.include?(level.downcase)
+ def name(difficult)
+ Codebreaker::Game::DIFFICULTS[difficult.to_sym][:name]
end
end