Class: Codebreaker::User
- Inherits:
-
Object
- Object
- Codebreaker::User
- Includes:
- Validation
- Defined in:
- lib/codebreaker/user.rb
Constant Summary
Constants included from Validation
Instance Attribute Summary collapse
-
#attempts ⇒ Object
readonly
Returns the value of attribute attempts.
-
#difficulty ⇒ Object
readonly
Returns the value of attribute difficulty.
-
#hints ⇒ Object
readonly
Returns the value of attribute hints.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #assign_user_config(difficulty) ⇒ Object
- #decrement_attemts ⇒ Object
- #decrement_hints ⇒ Object
-
#initialize(name) ⇒ User
constructor
A new instance of User.
Methods included from Validation
#validate_guess, #validate_name, #validate_state
Constructor Details
#initialize(name) ⇒ User
Returns a new instance of User.
9 10 11 12 |
# File 'lib/codebreaker/user.rb', line 9 def initialize(name) validate_name(name) @name = name end |
Instance Attribute Details
#attempts ⇒ Object (readonly)
Returns the value of attribute attempts.
7 8 9 |
# File 'lib/codebreaker/user.rb', line 7 def attempts @attempts end |
#difficulty ⇒ Object (readonly)
Returns the value of attribute difficulty.
7 8 9 |
# File 'lib/codebreaker/user.rb', line 7 def difficulty @difficulty end |
#hints ⇒ Object (readonly)
Returns the value of attribute hints.
7 8 9 |
# File 'lib/codebreaker/user.rb', line 7 def hints @hints end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/codebreaker/user.rb', line 7 def name @name end |
Instance Method Details
#assign_user_config(difficulty) ⇒ Object
14 15 16 17 18 |
# File 'lib/codebreaker/user.rb', line 14 def assign_user_config(difficulty) @difficulty = difficulty @attempts = Constants::DIFFICULTIES[@difficulty][:attempts] @hints = Constants::DIFFICULTIES[@difficulty][:hints] end |
#decrement_attemts ⇒ Object
20 21 22 |
# File 'lib/codebreaker/user.rb', line 20 def decrement_attemts @attempts -= 1 end |
#decrement_hints ⇒ Object
24 25 26 |
# File 'lib/codebreaker/user.rb', line 24 def decrement_hints @hints -= 1 end |