Class: DoDSWeapon
- Inherits:
-
Object
- Object
- DoDSWeapon
- 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
-
#headshots ⇒ Object
readonly
Returns the value of attribute headshots.
-
#hits ⇒ Object
readonly
Returns the value of attribute hits.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Attributes included from GameWeapon
Instance Method Summary collapse
-
#avg_hits_per_kill ⇒ Object
Returns the average number of hits needed for a kill with this weapon.
-
#headshot_percentage ⇒ Object
Returns the percentage of headshots relative to the shots hit with this weapon.
-
#hit_percentage ⇒ Object
Returns the percentage of hits relative to the shots fired with this weapon.
-
#initialize(weapon_data) ⇒ DoDSWeapon
constructor
Creates a new instance of DoDSWeapon based on the assigned XML data.
Methods included from GameWeapon
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
#headshots ⇒ Object (readonly)
Returns the value of attribute headshots.
13 14 15 |
# File 'lib/steam/community/dods/dods_weapon.rb', line 13 def headshots @headshots end |
#hits ⇒ Object (readonly)
Returns the value of attribute hits.
13 14 15 |
# File 'lib/steam/community/dods/dods_weapon.rb', line 13 def hits @hits end |
#name ⇒ Object (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_kill ⇒ Object
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_percentage ⇒ Object
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_percentage ⇒ Object
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 |