Class: CSSWeapon

Inherits:
Object
  • Object
show all
Defined in:
lib/steam/community/css/css_weapon.rb

Overview

CSSWeapon holds statistical information about weapons used by a player in Counter-Strike: Source.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(weapon_name, weapons_data) ⇒ CSSWeapon

Creates a new instance of CSSWeapon based on the assigned weapon name and XML data



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/steam/community/css/css_weapon.rb', line 14

def initialize(weapon_name, weapons_data)
  @name     = weapon_name

  @favorite = (weapons_data.elements['favorite'].text == @name)
  @kills    = weapons_data.elements["#{@name}_kills"].text.to_i

  if @name != 'grenade' && @name != 'knife'
    @hits     = weapons_data.elements["#{@name}_hits"].text.to_i
    @shots    = weapons_data.elements["#{@name}_shots"].text.to_i
    @accuracy = (@shots > 0) ? @hits.to_f / @shots : 0
    @ksratio  = (@shots > 0) ? @kills.to_f / @shots : 0
  end
end

Instance Attribute Details

#accuracyObject (readonly)

Returns the value of attribute accuracy.



10
11
12
# File 'lib/steam/community/css/css_weapon.rb', line 10

def accuracy
  @accuracy
end

#hitsObject (readonly)

Returns the value of attribute hits.



10
11
12
# File 'lib/steam/community/css/css_weapon.rb', line 10

def hits
  @hits
end

#killsObject (readonly)

Returns the value of attribute kills.



10
11
12
# File 'lib/steam/community/css/css_weapon.rb', line 10

def kills
  @kills
end

#ksratioObject (readonly)

Returns the value of attribute ksratio.



10
11
12
# File 'lib/steam/community/css/css_weapon.rb', line 10

def ksratio
  @ksratio
end

#nameObject (readonly)

Returns the value of attribute name.



10
11
12
# File 'lib/steam/community/css/css_weapon.rb', line 10

def name
  @name
end

#shotsObject (readonly)

Returns the value of attribute shots.



10
11
12
# File 'lib/steam/community/css/css_weapon.rb', line 10

def shots
  @shots
end

Instance Method Details

#favorite?Boolean

Returns whether this weapon is the favorite weapon of this player

Returns:

  • (Boolean)


29
30
31
# File 'lib/steam/community/css/css_weapon.rb', line 29

def favorite?
  @favorite
end