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

Author:

  • Sebastian Staudt

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 a Day of Defeat: Source weapon based on the given XML data

Parameters:

  • weapon_data (Hash<String, Object>)

    The XML data of the class



34
35
36
37
38
39
40
41
42
# File 'lib/steam/community/dods/dods_weapon.rb', line 34

def initialize(weapon_data)
  super weapon_data

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

Instance Attribute Details

#headshotsFixnum (readonly)

Returns the number of headshots achieved with this weapon

Returns:

  • (Fixnum)

    The number of headshots achieved



18
19
20
# File 'lib/steam/community/dods/dods_weapon.rb', line 18

def headshots
  @headshots
end

#hitsFixnum (readonly)

Returns the number of hits achieved with this weapon

Returns:

  • (Fixnum)

    The number of hits achieved



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

def hits
  @hits
end

#nameString (readonly)

Returns the name of this weapon

Returns:

  • (String)

    The name of this weapon



23
24
25
# File 'lib/steam/community/dods/dods_weapon.rb', line 23

def name
  @name
end

Instance Method Details

#avg_hits_per_killFloat

Returns the average number of hits needed for a kill with this weapon

Returns:

  • (Float)

    The average number of hits needed for a kill



47
48
49
# File 'lib/steam/community/dods/dods_weapon.rb', line 47

def avg_hits_per_kill
  @hits.to_f / @kill
end

#headshot_percentageFloat

Returns the percentage of headshots relative to the shots hit with this weapon

Returns:

  • (Float)

    The percentage of headshots



55
56
57
# File 'lib/steam/community/dods/dods_weapon.rb', line 55

def headshot_percentage
  @headshots.to_f / @hits
end

#hit_percentageFloat

Returns the percentage of hits relative to the shots fired with this weapon

Returns:

  • (Float)

    The percentage of hits



63
64
65
# File 'lib/steam/community/dods/dods_weapon.rb', line 63

def hit_percentage
  @hits.to_f / @shots
end