Class: Codebreaker::Player
- Inherits:
-
Object
- Object
- Codebreaker::Player
- Defined in:
- lib/entities/player.rb
Instance Attribute Summary collapse
-
#attempts_ttl ⇒ Object
Returns the value of attribute attempts_ttl.
-
#attempts_used ⇒ Object
Returns the value of attribute attempts_used.
-
#date ⇒ Object
Returns the value of attribute date.
-
#difficulty ⇒ Object
Returns the value of attribute difficulty.
-
#hints_ttl ⇒ Object
Returns the value of attribute hints_ttl.
-
#hints_used ⇒ Object
Returns the value of attribute hints_used.
-
#name ⇒ Object
Returns the value of attribute name.
-
#rating ⇒ Object
Returns the value of attribute rating.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(name, difficulty, game) ⇒ Player
constructor
A new instance of Player.
- #on_win(attempts:, hints:) ⇒ Object
Constructor Details
#initialize(name, difficulty, game) ⇒ Player
Returns a new instance of Player.
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/entities/player.rb', line 14 def initialize(name, difficulty, game) @name = name @difficulty = difficulty @attempts_ttl = game.attempts_total @attempts_used = nil @hints_ttl = game.hints_available @hints_used = nil @rating = nil @date = nil end |
Instance Attribute Details
#attempts_ttl ⇒ Object
Returns the value of attribute attempts_ttl.
3 4 5 |
# File 'lib/entities/player.rb', line 3 def attempts_ttl @attempts_ttl end |
#attempts_used ⇒ Object
Returns the value of attribute attempts_used.
3 4 5 |
# File 'lib/entities/player.rb', line 3 def attempts_used @attempts_used end |
#date ⇒ Object
Returns the value of attribute date.
3 4 5 |
# File 'lib/entities/player.rb', line 3 def date @date end |
#difficulty ⇒ Object
Returns the value of attribute difficulty.
3 4 5 |
# File 'lib/entities/player.rb', line 3 def difficulty @difficulty end |
#hints_ttl ⇒ Object
Returns the value of attribute hints_ttl.
3 4 5 |
# File 'lib/entities/player.rb', line 3 def hints_ttl @hints_ttl end |
#hints_used ⇒ Object
Returns the value of attribute hints_used.
3 4 5 |
# File 'lib/entities/player.rb', line 3 def hints_used @hints_used end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/entities/player.rb', line 3 def name @name end |
#rating ⇒ Object
Returns the value of attribute rating.
3 4 5 |
# File 'lib/entities/player.rb', line 3 def @rating end |
Class Method Details
.valid?(name) ⇒ Boolean
34 35 36 |
# File 'lib/entities/player.rb', line 34 def self.valid?(name) name.instance_of?(String) && name.length > 2 && name.length < 21 end |
Instance Method Details
#<=>(other) ⇒ Object
25 26 27 |
# File 'lib/entities/player.rb', line 25 def <=>(other) [other.hints_used, other.attempts_used] <=> [@hints_used, @attempts_used] end |
#on_win(attempts:, hints:) ⇒ Object
29 30 31 32 |
# File 'lib/entities/player.rb', line 29 def on_win(attempts:, hints:) @attempts_used = @attempts_ttl - attempts @hints_used = hints end |