Class: DoDSWeapon

Inherits:
Object
  • Object
show all
Includes:
GameWeapon
Defined in:
lib/steam/community/dods/dods_weapon.rb

Overview

Represents the stats for a Day of Defeat: Source weapon for a specific user

Instance Attribute Summary collapse

Attributes included from GameWeapon

#id, #kills, #shots

Instance Method Summary collapse

Methods included from GameWeapon

#avg_shots_per_kill

Constructor Details

#initialize(weapon_data) ⇒ DoDSWeapon

Creates a new instance of DoDSWeapon based on the assigned XML data



16
17
18
19
20
21
22
23
24
# File 'lib/steam/community/dods/dods_weapon.rb', line 16

def initialize(weapon_data)
  super weapon_data

  @headshots = weapon_data.elements['headshots'].text.to_i
  @id        = weapon_data.attributes['key']
  @name      = weapon_data.elements['name'].text
  @shots     = weapon_data.elements['shotsfired'].text.to_i
  @hits      = weapon_data.elements['shotshit'].text.to_i
end

Instance Attribute Details

#headshotsObject (readonly)

Returns the value of attribute headshots.



13
14
15
# File 'lib/steam/community/dods/dods_weapon.rb', line 13

def headshots
  @headshots
end

#hitsObject (readonly)

Returns the value of attribute hits.



13
14
15
# File 'lib/steam/community/dods/dods_weapon.rb', line 13

def hits
  @hits
end

#nameObject (readonly)

Returns the value of attribute name.



13
14
15
# File 'lib/steam/community/dods/dods_weapon.rb', line 13

def name
  @name
end

Instance Method Details

#avg_hits_per_killObject

Returns the average number of hits needed for a kill with this weapon. Calculates the value if needed.



28
29
30
31
32
33
34
# File 'lib/steam/community/dods/dods_weapon.rb', line 28

def avg_hits_per_kill
  if @avg_hits_per_kill.nil?
    @avg_hits_per_kill = @hits.to_f / @kills
  end

  @avg_hits_per_kill
end

#headshot_percentageObject

Returns the percentage of headshots relative to the shots hit with this weapon. Calculates the value if needed.



38
39
40
41
42
43
44
# File 'lib/steam/community/dods/dods_weapon.rb', line 38

def headshot_percentage
  if @headshot_percentage.nil?
    @headshot_percentage = @headshots.to_f / @hits
  end

  @headshot_percentage
end

#hit_percentageObject

Returns the percentage of hits relative to the shots fired with this weapon. Calculates the value if needed.



48
49
50
51
52
53
54
# File 'lib/steam/community/dods/dods_weapon.rb', line 48

def hit_percentage
  if @hit_percentage.nil?
    @hit_percentage = @hits.to_f / @shots
  end

  @hit_percentage
end