Class: CSSWeapon
- Inherits:
-
Object
- Object
- CSSWeapon
- Defined in:
- lib/steam/community/css/css_weapon.rb
Overview
Represents the stats for a Counter-Strike: Source weapon for a specific user
Instance Attribute Summary collapse
-
#hits ⇒ Fixnum
readonly
Returns the number of hits achieved with this weapon.
-
#kills ⇒ Fixnum
readonly
Returns the number of kills achieved with this weapon.
-
#name ⇒ String
readonly
Returns the name of this weapon.
-
#shots ⇒ Fixnum
readonly
Returns the number of shots fired with this weapon.
Instance Method Summary collapse
-
#accuracy ⇒ Float
Returns the accuracy of this player with this weapon.
-
#favorite? ⇒ Boolean
Returns whether this weapon is the favorite weapon of this player.
-
#initialize(weapon_name, weapons_data) ⇒ CSSWeapon
constructor
Creates a new instance of a Counter-Strike: Source weapon based on the given XML data.
-
#ksratio ⇒ Float
Returns the kill-shot-ratio of this player with this weapon.
Constructor Details
#initialize(weapon_name, weapons_data) ⇒ CSSWeapon
Creates a new instance of a Counter-Strike: Source weapon based on the given XML data
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/steam/community/css/css_weapon.rb', line 36 def initialize(weapon_name, weapons_data) @name = weapon_name @favorite = (weapons_data['favorite'] == @name) @kills = weapons_data["#{@name}_kills"].to_i if @name != 'grenade' && @name != 'knife' @hits = weapons_data["#{@name}_hits"].to_i @shots = weapons_data["#{@name}_shots"].to_i end end |
Instance Attribute Details
#hits ⇒ Fixnum (readonly)
Returns the number of hits achieved with this weapon
14 15 16 |
# File 'lib/steam/community/css/css_weapon.rb', line 14 def hits @hits end |
#kills ⇒ Fixnum (readonly)
Returns the number of kills achieved with this weapon
24 25 26 |
# File 'lib/steam/community/css/css_weapon.rb', line 24 def kills @kills end |
#name ⇒ String (readonly)
Returns the name of this weapon
19 20 21 |
# File 'lib/steam/community/css/css_weapon.rb', line 19 def name @name end |
#shots ⇒ Fixnum (readonly)
Returns the number of shots fired with this weapon
29 30 31 |
# File 'lib/steam/community/css/css_weapon.rb', line 29 def shots @shots end |
Instance Method Details
#accuracy ⇒ Float
Returns the accuracy of this player with this weapon
51 52 53 |
# File 'lib/steam/community/css/css_weapon.rb', line 51 def accuracy (@shots > 0) ? @hits.to_f / @shots : 0 end |
#favorite? ⇒ Boolean
Returns whether this weapon is the favorite weapon of this player
58 59 60 |
# File 'lib/steam/community/css/css_weapon.rb', line 58 def favorite? @favorite end |
#ksratio ⇒ Float
Returns the kill-shot-ratio of this player with this weapon
65 66 67 |
# File 'lib/steam/community/css/css_weapon.rb', line 65 def ksratio (@shots > 0) ? @kills.to_f / @shots : 0 end |