Class: CSSWeapon

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

Overview

Represents the stats for a Counter-Strike: Source weapon for a specific user

Author:

  • Sebastian Staudt

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(weapon_name, weapons_data) ⇒ CSSWeapon

Creates a new instance of a Counter-Strike: Source weapon based on the given XML data

Parameters:

  • weapon_name (String)

    The name of the weapon

  • weapons_data (Hash<String, Object>)

    The XML data of all weapons



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

#hitsFixnum (readonly)

Returns the number of hits achieved with this weapon

Returns:

  • (Fixnum)

    The number of hits achieved



14
15
16
# File 'lib/steam/community/css/css_weapon.rb', line 14

def hits
  @hits
end

#killsFixnum (readonly)

Returns the number of kills achieved with this weapon

Returns:

  • (Fixnum)

    The number of kills achieved



24
25
26
# File 'lib/steam/community/css/css_weapon.rb', line 24

def kills
  @kills
end

#nameString (readonly)

Returns the name of this weapon

Returns:

  • (String)

    The name of this weapon



19
20
21
# File 'lib/steam/community/css/css_weapon.rb', line 19

def name
  @name
end

#shotsFixnum (readonly)

Returns the number of shots fired with this weapon

Returns:

  • (Fixnum)

    The number of shots fired



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

def shots
  @shots
end

Instance Method Details

#accuracyFloat

Returns the accuracy of this player with this weapon

Returns:

  • (Float)

    The accuracy 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

Returns:

  • (Boolean)

    ‘true` if this is the favorite weapon



58
59
60
# File 'lib/steam/community/css/css_weapon.rb', line 58

def favorite?
  @favorite
end

#ksratioFloat

Returns the kill-shot-ratio of this player with this weapon

Returns:

  • (Float)

    The kill-shot-ratio



65
66
67
# File 'lib/steam/community/css/css_weapon.rb', line 65

def ksratio
  (@shots > 0) ? @kills.to_f / @shots : 0
end