Class: Codebreaker::User

Inherits:
BaseEntity show all
Defined in:
lib/codebreaker/user.rb

Constant Summary collapse

NAME_MIN_LENGTH =
3
NAME_MAX_LENGTH =
20

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Validation

#valid_class?, #valid_non_empty_string?, #valid_non_negative_integer?, #valid_only_numeric_string?, #valid_positive_integer?, #valid_range?, #valid_string_max_length?, #valid_string_min_length?

Constructor Details

#initialize(name, difficulty) ⇒ User

Returns a new instance of User.



12
13
14
15
16
17
18
# File 'lib/codebreaker/user.rb', line 12

def initialize(name, difficulty)
  @name = name
  @difficulty = difficulty
  @used_attempts = 0
  @used_hints = 0
  super
end

Instance Attribute Details

#difficultyObject (readonly)

Returns the value of attribute difficulty.



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

def difficulty
  @difficulty
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#used_attemptsObject (readonly)

Returns the value of attribute used_attempts.



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

def used_attempts
  @used_attempts
end

#used_hintsObject (readonly)

Returns the value of attribute used_hints.



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

def used_hints
  @used_hints
end

Instance Method Details

#attemptObject



32
33
34
# File 'lib/codebreaker/user.rb', line 32

def attempt
  @used_attempts += 1
end

#attempts?Boolean

Returns:

  • (Boolean)


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

def attempts?
  difficulty.attempts = used_attempts
end

#hintObject



28
29
30
# File 'lib/codebreaker/user.rb', line 28

def hint
  @used_hints += 1
end

#hints?Boolean

Returns:

  • (Boolean)


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

def hints?
  difficulty.hints = used_hints
end