Class: Codebreaker::User

Inherits:
Object
  • Object
show all
Includes:
Validation
Defined in:
lib/codebreaker/user.rb

Constant Summary

Constants included from Validation

Validation::NUMBERS

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#attemptsObject (readonly)

Returns the value of attribute attempts.



7
8
9
# File 'lib/codebreaker/user.rb', line 7

def attempts
  @attempts
end

#difficultyObject (readonly)

Returns the value of attribute difficulty.



7
8
9
# File 'lib/codebreaker/user.rb', line 7

def difficulty
  @difficulty
end

#hintsObject (readonly)

Returns the value of attribute hints.



7
8
9
# File 'lib/codebreaker/user.rb', line 7

def hints
  @hints
end

#nameObject (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_attemtsObject



20
21
22
# File 'lib/codebreaker/user.rb', line 20

def decrement_attemts
  @attempts -= 1
end

#decrement_hintsObject



24
25
26
# File 'lib/codebreaker/user.rb', line 24

def decrement_hints
  @hints -= 1
end