Class: Stats
- Inherits:
-
Object
- Object
- Stats
- Defined in:
- lib/misc/stats.rb
Instance Attribute Summary collapse
-
#changed_at ⇒ Object
readonly
Returns the value of attribute changed_at.
-
#deaths ⇒ Object
readonly
Returns the value of attribute deaths.
-
#kills ⇒ Object
readonly
Returns the value of attribute kills.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#shots ⇒ Object
readonly
Returns the value of attribute shots.
Instance Method Summary collapse
- #add_damage(amount) ⇒ Object
- #add_damage_dealt(amount) ⇒ Object
- #add_death ⇒ Object
- #add_kill(amount = 1) ⇒ Object
- #add_shot ⇒ Object
- #damage ⇒ Object
- #damage_dealt ⇒ Object
-
#initialize(name) ⇒ Stats
constructor
A new instance of Stats.
- #to_s ⇒ Object
Constructor Details
#initialize(name) ⇒ Stats
Returns a new instance of Stats.
3 4 5 6 7 |
# File 'lib/misc/stats.rb', line 3 def initialize(name) @name = name @kills = @deaths = @shots = @damage = @damage_dealt = 0 changed end |
Instance Attribute Details
#changed_at ⇒ Object (readonly)
Returns the value of attribute changed_at.
2 3 4 |
# File 'lib/misc/stats.rb', line 2 def changed_at @changed_at end |
#deaths ⇒ Object (readonly)
Returns the value of attribute deaths.
2 3 4 |
# File 'lib/misc/stats.rb', line 2 def deaths @deaths end |
#kills ⇒ Object (readonly)
Returns the value of attribute kills.
2 3 4 |
# File 'lib/misc/stats.rb', line 2 def kills @kills end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
2 3 4 |
# File 'lib/misc/stats.rb', line 2 def name @name end |
#shots ⇒ Object (readonly)
Returns the value of attribute shots.
2 3 4 |
# File 'lib/misc/stats.rb', line 2 def shots @shots end |
Instance Method Details
#add_damage(amount) ⇒ Object
24 25 26 27 |
# File 'lib/misc/stats.rb', line 24 def add_damage(amount) @damage += amount changed end |
#add_damage_dealt(amount) ⇒ Object
33 34 35 36 |
# File 'lib/misc/stats.rb', line 33 def add_damage_dealt(amount) @damage_dealt += amount changed end |
#add_death ⇒ Object
14 15 16 17 |
# File 'lib/misc/stats.rb', line 14 def add_death @deaths += 1 changed end |
#add_kill(amount = 1) ⇒ Object
9 10 11 12 |
# File 'lib/misc/stats.rb', line 9 def add_kill(amount = 1) @kills += amount changed end |
#add_shot ⇒ Object
19 20 21 22 |
# File 'lib/misc/stats.rb', line 19 def add_shot @shots += 1 changed end |
#damage ⇒ Object
29 30 31 |
# File 'lib/misc/stats.rb', line 29 def damage @damage.round end |
#damage_dealt ⇒ Object
38 39 40 |
# File 'lib/misc/stats.rb', line 38 def damage_dealt @damage_dealt.round end |
#to_s ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/misc/stats.rb', line 42 def to_s "[kills: #{@kills}, " \ "deaths: #{@deaths}, " \ "shots: #{@shots}, " \ "damage: #{damage}, " \ "damage_dealt: #{damage_dealt}]" end |