Class: Stats

Inherits:
Object
  • Object
show all
Defined in:
lib/misc/stats.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_atObject (readonly)

Returns the value of attribute changed_at.



2
3
4
# File 'lib/misc/stats.rb', line 2

def changed_at
  @changed_at
end

#deathsObject (readonly)

Returns the value of attribute deaths.



2
3
4
# File 'lib/misc/stats.rb', line 2

def deaths
  @deaths
end

#killsObject (readonly)

Returns the value of attribute kills.



2
3
4
# File 'lib/misc/stats.rb', line 2

def kills
  @kills
end

#nameObject (readonly)

Returns the value of attribute name.



2
3
4
# File 'lib/misc/stats.rb', line 2

def name
  @name
end

#shotsObject (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_deathObject



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_shotObject



19
20
21
22
# File 'lib/misc/stats.rb', line 19

def add_shot
  @shots += 1
  changed
end

#damageObject



29
30
31
# File 'lib/misc/stats.rb', line 29

def damage
  @damage.round
end

#damage_dealtObject



38
39
40
# File 'lib/misc/stats.rb', line 38

def damage_dealt
  @damage_dealt.round
end

#to_sObject



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