Class: AndriiCodebreaker::Difficulty

Inherits:
Object
  • Object
show all
Includes:
Constant
Defined in:
lib/andrii_codebreaker/difficulty.rb

Constant Summary

Constants included from Constant

Constant::CODE_LENGTH, Constant::CODE_LENGTH_COUNT, Constant::CODE_START_LENGTH, Constant::DIFFICULTY, Constant::DIFFICULTY_SORT, Constant::LALA, Constant::MINUS, Constant::NAME_MAX_LENGTH, Constant::NAME_MIN_LENGTH, Constant::PLUS, Constant::RANGE_SECRET_CODE, Constant::WIN

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Difficulty

Returns a new instance of Difficulty.



9
10
11
12
13
14
# File 'lib/andrii_codebreaker/difficulty.rb', line 9

def initialize(name)
  validate_difficulty(name)
  @name = name
  @hints = DIFFICULTY[name.to_sym][:hints]
  @attempts = DIFFICULTY[name.to_sym][:attempts]
end

Instance Attribute Details

#attemptsObject (readonly)

Returns the value of attribute attempts.



7
8
9
# File 'lib/andrii_codebreaker/difficulty.rb', line 7

def attempts
  @attempts
end

#hintsObject (readonly)

Returns the value of attribute hints.



7
8
9
# File 'lib/andrii_codebreaker/difficulty.rb', line 7

def hints
  @hints
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/andrii_codebreaker/difficulty.rb', line 7

def name
  @name
end

Instance Method Details

#validate_difficulty(name) ⇒ Object

Raises:

  • (ArgumentError)


16
17
18
19
20
# File 'lib/andrii_codebreaker/difficulty.rb', line 16

def validate_difficulty(name)
  return DIFFICULTY[name.to_sym] if DIFFICULTY.keys.include? name.to_sym

  raise ArgumentError
end