steam-condenser 0.14.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. data/Gemfile +3 -0
  2. data/Gemfile.lock +22 -0
  3. data/LICENSE +1 -1
  4. data/README.md +14 -6
  5. data/Rakefile +35 -0
  6. data/lib/{stringio_additions.rb → core_ext/stringio.rb} +1 -1
  7. data/lib/{exceptions/packet_format_exception.rb → errors/packet_format_error.rb} +5 -5
  8. data/lib/{exceptions/rcon_ban_exception.rb → errors/rcon_ban_error.rb} +5 -5
  9. data/lib/{exceptions/rcon_no_auth_exception.rb → errors/rcon_no_auth_error.rb} +5 -5
  10. data/lib/{exceptions/steam_condenser_exception.rb → errors/steam_condenser_error.rb} +3 -3
  11. data/lib/errors/timeout_error.rb +28 -0
  12. data/lib/{exceptions/web_api_exception.rb → errors/web_api_error.rb} +8 -8
  13. data/lib/steam/community/alien_swarm/alien_swarm_mission.rb +86 -11
  14. data/lib/steam/community/alien_swarm/alien_swarm_stats.rb +38 -15
  15. data/lib/steam/community/alien_swarm/alien_swarm_weapon.rb +29 -8
  16. data/lib/steam/community/app_news.rb +91 -27
  17. data/lib/steam/community/cacheable.rb +65 -21
  18. data/lib/steam/community/css/css_map.rb +39 -9
  19. data/lib/steam/community/css/css_stats.rb +32 -12
  20. data/lib/steam/community/css/css_weapon.rb +46 -10
  21. data/lib/steam/community/defense_grid/defense_grid_stats.rb +129 -17
  22. data/lib/steam/community/dods/dods_class.rb +66 -10
  23. data/lib/steam/community/dods/dods_stats.rb +20 -7
  24. data/lib/steam/community/dods/dods_weapon.rb +35 -24
  25. data/lib/steam/community/game_achievement.rb +50 -19
  26. data/lib/steam/community/game_class.rb +16 -5
  27. data/lib/steam/community/game_inventory.rb +37 -4
  28. data/lib/steam/community/game_item.rb +64 -3
  29. data/lib/steam/community/game_stats.rb +81 -16
  30. data/lib/steam/community/game_weapon.rb +29 -11
  31. data/lib/steam/community/l4d/abstract_l4d_stats.rb +91 -65
  32. data/lib/steam/community/l4d/abstract_l4d_weapon.rb +38 -8
  33. data/lib/steam/community/l4d/l4d2_map.rb +30 -5
  34. data/lib/steam/community/l4d/l4d2_stats.rb +83 -45
  35. data/lib/steam/community/l4d/l4d2_weapon.rb +20 -6
  36. data/lib/steam/community/l4d/l4d_explosive.rb +13 -5
  37. data/lib/steam/community/l4d/l4d_map.rb +35 -7
  38. data/lib/steam/community/l4d/l4d_stats.rb +23 -10
  39. data/lib/steam/community/l4d/l4d_weapon.rb +11 -7
  40. data/lib/steam/community/portal2/portal2_inventory.rb +4 -0
  41. data/lib/steam/community/portal2/portal2_item.rb +13 -1
  42. data/lib/steam/community/portal2/portal2_stats.rb +10 -6
  43. data/lib/steam/community/steam_game.rb +74 -0
  44. data/lib/steam/community/steam_group.rb +48 -14
  45. data/lib/steam/community/steam_id.rb +295 -64
  46. data/lib/steam/community/tf2/tf2_class.rb +66 -7
  47. data/lib/steam/community/tf2/tf2_class_factory.rb +14 -7
  48. data/lib/steam/community/tf2/tf2_engineer.rb +26 -6
  49. data/lib/steam/community/tf2/tf2_golden_wrench.rb +37 -10
  50. data/lib/steam/community/tf2/tf2_inventory.rb +4 -0
  51. data/lib/steam/community/tf2/tf2_item.rb +13 -1
  52. data/lib/steam/community/tf2/tf2_medic.rb +20 -5
  53. data/lib/steam/community/tf2/tf2_sniper.rb +15 -5
  54. data/lib/steam/community/tf2/tf2_spy.rb +20 -6
  55. data/lib/steam/community/tf2/tf2_stats.rb +20 -6
  56. data/lib/steam/community/web_api.rb +50 -32
  57. data/lib/steam/packets/c2m_checkmd5_packet.rb +1 -1
  58. data/lib/steam/packets/m2a_server_batch_packet.rb +3 -2
  59. data/lib/steam/packets/m2s_requestrestart_packet.rb +3 -3
  60. data/lib/steam/packets/rcon/rcon_packet_factory.rb +4 -4
  61. data/lib/steam/packets/request_with_challenge.rb +1 -1
  62. data/lib/steam/packets/s2a_info_base_packet.rb +1 -1
  63. data/lib/steam/packets/s2a_info_detailed_packet.rb +10 -10
  64. data/lib/steam/packets/s2a_player_packet.rb +5 -1
  65. data/lib/steam/packets/s2a_rules_packet.rb +4 -3
  66. data/lib/steam/packets/s2m_heartbeat2_packet.rb +2 -2
  67. data/lib/steam/packets/steam_packet.rb +1 -1
  68. data/lib/steam/packets/steam_packet_factory.rb +12 -16
  69. data/lib/steam/servers/game_server.rb +38 -32
  70. data/lib/steam/servers/goldsrc_server.rb +10 -1
  71. data/lib/steam/servers/master_server.rb +42 -21
  72. data/lib/steam/servers/server.rb +4 -5
  73. data/lib/steam/servers/source_server.rb +20 -5
  74. data/lib/steam/sockets/goldsrc_socket.rb +53 -22
  75. data/lib/steam/sockets/master_server_socket.rb +14 -4
  76. data/lib/steam/sockets/rcon_socket.rb +39 -6
  77. data/lib/steam/sockets/source_socket.rb +19 -15
  78. data/lib/steam/sockets/steam_socket.rb +33 -23
  79. data/lib/steam/steam_player.rb +86 -11
  80. data/lib/steam-condenser/community.rb +24 -24
  81. data/lib/steam-condenser/servers.rb +2 -2
  82. data/lib/steam-condenser/version.rb +3 -3
  83. data/steam-condenser.gemspec +23 -0
  84. data/test/query_tests.rb +12 -12
  85. data/test/rcon_tests.rb +3 -3
  86. data/test/steam/communtiy/steam_community_test_suite.rb +12 -0
  87. data/test/steam/communtiy/steam_group_tests.rb +6 -5
  88. data/test/steam/communtiy/steam_id_tests.rb +6 -5
  89. data/test/steam_community_tests.rb +3 -3
  90. data/test/stringio_additions_tests.rb +7 -7
  91. metadata +61 -43
  92. data/lib/exceptions/timeout_exception.rb +0 -24
  93. data/test/datagram_channel_tests.rb +0 -42
  94. data/test/socket_channel_tests.rb +0 -43
@@ -1,16 +1,38 @@
1
- # This code is free software; you can redistribute it and/or modify it under the
2
- # terms of the new BSD License.
1
+ # This code is free software; you can redistribute it and/or modify it under
2
+ # the terms of the new BSD License.
3
3
  #
4
- # Copyright (c) 2010, Sebastian Staudt
4
+ # Copyright (c) 2010-2011, Sebastian Staudt
5
5
 
6
- # CSSWeapon holds statistical information about weapons used by a player in
7
- # Counter-Strike: Source.
6
+ # Represents the stats for a Counter-Strike: Source weapon for a specific user
7
+ #
8
+ # @author Sebastian Staudt
8
9
  class CSSWeapon
9
10
 
10
- attr_reader :accuracy, :hits, :name, :kills, :ksratio, :shots
11
+ # Returns the number of hits achieved with this weapon
12
+ #
13
+ # @return [Fixnum] The number of hits achieved
14
+ attr_reader :hits
15
+
16
+ # Returns the name of this weapon
17
+ #
18
+ # @return [String] The name of this weapon
19
+ attr_reader :name
20
+
21
+ # Returns the number of kills achieved with this weapon
22
+ #
23
+ # @return [Fixnum] The number of kills achieved
24
+ attr_reader :kills
25
+
26
+ # Returns the number of shots fired with this weapon
27
+ #
28
+ # @return [Fixnum] The number of shots fired
29
+ attr_reader :shots
11
30
 
12
- # Creates a new instance of CSSWeapon based on the assigned weapon name and
13
- # XML data
31
+ # Creates a new instance of a Counter-Strike: Source weapon based on the
32
+ # given XML data
33
+ #
34
+ # @param [String] weapon_name The name of the weapon
35
+ # @param [REXML::Element] weapons_data The XML data of all weapons
14
36
  def initialize(weapon_name, weapons_data)
15
37
  @name = weapon_name
16
38
 
@@ -20,14 +42,28 @@ class CSSWeapon
20
42
  if @name != 'grenade' && @name != 'knife'
21
43
  @hits = weapons_data.elements["#{@name}_hits"].text.to_i
22
44
  @shots = weapons_data.elements["#{@name}_shots"].text.to_i
23
- @accuracy = (@shots > 0) ? @hits.to_f / @shots : 0
24
- @ksratio = (@shots > 0) ? @kills.to_f / @shots : 0
25
45
  end
26
46
  end
27
47
 
48
+ # Returns the accuracy of this player with this weapon
49
+ #
50
+ # @return [Float] The accuracy with this weapon
51
+ def accuracy
52
+ (@shots > 0) ? @hits.to_f / @shots : 0
53
+ end
54
+
28
55
  # Returns whether this weapon is the favorite weapon of this player
56
+ #
57
+ # @return [Boolean] `true` if this is the favorite weapon
29
58
  def favorite?
30
59
  @favorite
31
60
  end
32
61
 
62
+ # Returns the kill-shot-ratio of this player with this weapon
63
+ #
64
+ # @return [Float] The kill-shot-ratio
65
+ def ksratio
66
+ (@shots > 0) ? @kills.to_f / @shots : 0
67
+ end
68
+
33
69
  end
@@ -1,23 +1,131 @@
1
- # This code is free software; you can redistribute it and/or modify it under the
2
- # terms of the new BSD License.
1
+ # This code is free software; you can redistribute it and/or modify it under
2
+ # the terms of the new BSD License.
3
3
  #
4
- # Copyright (c) 2009-2010, Sebastian Staudt
4
+ # Copyright (c) 2009-2011, Sebastian Staudt
5
5
 
6
6
  require 'steam/community/game_stats'
7
7
 
8
- # The DefenseGridStats class represents the game statistics for a single user in
9
- # Defense Grid: The Awakening
8
+ # This class represents the game statistics for a single user in Defense Grid:
9
+ # The Awakening
10
+ #
11
+ # @author Sebastian Staudt
10
12
  class DefenseGridStats < GameStats
11
13
 
12
- attr_reader :bronze_medals, :damage_done, :damage_campaign, :damage_challenge,
13
- :encountered, :gold_medals, :heat_damage, :interest, :killed,
14
- :killed_campaign, :killed_challenge, :levels_played,
15
- :levels_played_campaign, :levels_played_challenge, :levels_won,
16
- :levels_won_campaign, :levels_won_challenge, :orbital_laser_fired,
17
- :orbital_laser_damage, :resources, :silver_medals, :time_played
14
+ # Returns the bronze medals won by this player
15
+ #
16
+ # @return [Fixnum] Bronze medals won
17
+ attr_reader :bronze_medals
18
+
19
+ # Returns the damage done by this player
20
+ #
21
+ # @return [Float] Damage done
22
+ attr_reader :damage_done
23
+
24
+ # Returns the damage done during the campaign by this player
25
+ #
26
+ # @return [Float] Damage done during the campaign
27
+ attr_reader :damage_campaign
28
+
29
+ # Returns the damage done during challenges by this player
30
+ #
31
+ # @return [Float] Damage done during challenges
32
+ attr_reader :damage_challenge
33
+
34
+ # Returns the aliens encountered by this player
35
+ #
36
+ # @return [Fixnum] Aliens encountered
37
+ attr_reader :encountered
38
+
39
+ # Returns the gold medals won by this player
40
+ #
41
+ # @return [Fixnum] Gold medals won
42
+ attr_reader :gold_medals
43
+
44
+ # Returns the heat damage done by this player
45
+ #
46
+ # @return [Float] Heat damage done
47
+ attr_reader :heat_damage
48
+
49
+ # Returns the interest gained by the player
50
+ #
51
+ # @return [Fixnum] Interest gained
52
+ attr_reader :interest
53
+
54
+ # Returns the aliens killed by the player
55
+ #
56
+ # @return [Fixnum] Aliens killed
57
+ attr_reader :killed
58
+
59
+ # Returns the aliens killed during the campaign by the player
60
+ #
61
+ # @return [Fixnum] Aliens killed during the campaign
62
+ attr_reader :killed_campaign
63
+
64
+ # Returns the aliens killed during challenges by the player
65
+ #
66
+ # @return [Fixnum] Aliens killed during challenges
67
+ attr_reader :killed_challenge
68
+
69
+ # Returns the number of levels played by the player
70
+ #
71
+ # @return [Fixnum] Number of levels played
72
+ attr_reader :levels_played
18
73
 
19
- # Creates a DefenseGridStats object by calling the super constructor with the
20
- # game name "defensegrid:awakening"
74
+ # Returns the number of levels played during the campaign by the player
75
+ #
76
+ # @return [Fixnum] Number of levels played during the campaign
77
+ attr_reader :levels_played_campaign
78
+
79
+ # Returns the number of levels played during challenges by the player
80
+ #
81
+ # @return [Fixnum] Number of levels played during challenges
82
+ attr_reader :levels_played_challenge
83
+
84
+ # Returns the number of levels won by the player
85
+ #
86
+ # @return [Fixnum] Number of levels won
87
+ attr_reader :levels_won
88
+
89
+ # Returns the number of levels won during the campaign by the player
90
+ #
91
+ # @return [Fixnum] Number of levels during the campaign won
92
+ attr_reader :levels_won_campaign
93
+
94
+ # Returns the number of levels won during challenges by the player
95
+ #
96
+ # @return [Fixnum] Number of levels during challenges won
97
+ attr_reader :levels_won_challenge
98
+
99
+ # Returns the damage dealt by the orbital laser
100
+ #
101
+ # @return [Float] Damage dealt by the orbital laser
102
+ attr_reader :orbital_laser_fired
103
+
104
+ # Returns the number of times the orbital lasers has been fired by the player
105
+ #
106
+ # @return [Fixnum] Number of times the orbital laser has been fired
107
+ attr_reader :orbital_laser_damage
108
+
109
+ # Returns the amount of resources harvested by the player
110
+ #
111
+ # @return [Fixnum] Resources harvested by the player
112
+ attr_reader :resources
113
+
114
+ # Returns the silver medals won by this player
115
+ #
116
+ # @return [Fixnum] Silver medals won
117
+ attr_reader :silver_medals
118
+
119
+ # Returns the time played in seconds by the player
120
+ #
121
+ # @return [Float] Time played
122
+ attr_reader :time_played
123
+
124
+ # Creates a `DefenseGridStats` instance by calling the super constructor with
125
+ # the game name `'defensegrid:awakening'`
126
+ #
127
+ # @param [String, Fixnum] steam_id The custom URL or the 64bit Steam ID of
128
+ # the user
21
129
  def initialize(steam_id)
22
130
  super(steam_id, 'defensegrid:awakening')
23
131
 
@@ -28,7 +136,7 @@ class DefenseGridStats < GameStats
28
136
  @silver_medals = general_data.elements['silver_medals_won/value'].text.to_i
29
137
  @gold_medals = general_data.elements['gold_medals_won/value'].text.to_i
30
138
  @levels_played = general_data.elements['levels_played_total/value'].text.to_i
31
- @levels_played_campagin = general_data.elements['levels_played_campaign/value'].text.to_i
139
+ @levels_played_campaign = general_data.elements['levels_played_campaign/value'].text.to_i
32
140
  @levels_played_challenge = general_data.elements['levels_played_challenge/value'].text.to_i
33
141
  @levels_won = general_data.elements['levels_won_total/value'].text.to_i
34
142
  @levels_won_campaign = general_data.elements['levels_won_campaign/value'].text.to_i
@@ -41,7 +149,7 @@ class DefenseGridStats < GameStats
41
149
  @heat_damage = general_data.elements['heatdamage/value'].text.to_f
42
150
  @time_played = general_data.elements['time_played/value'].text.to_f
43
151
  @interest = general_data.elements['interest_gained/value'].text.to_f
44
- @damage = general_data.elements['tower_damage_total/value'].text.to_f
152
+ @damage_done = general_data.elements['tower_damage_total/value'].text.to_f
45
153
  @damage_campaign = general_data.elements['tower_damage_total_campaign/value'].text.to_f
46
154
  @damage_challenge = general_data.elements['tower_damage_total_challenge/value'].text.to_f
47
155
  @orbital_laser_fired = @xml_data.elements['stats/orbitallaser/fired/value'].text.to_i
@@ -49,11 +157,13 @@ class DefenseGridStats < GameStats
49
157
  end
50
158
  end
51
159
 
52
- # Returns stats about the towers built
160
+ # Returns stats about the aliens encountered by the player
53
161
  #
54
162
  # The Hash returned uses the names of the aliens as keys. Every value of the
55
163
  # Hash is an Array containing the number of aliens encountered as the first
56
164
  # element and the number of aliens killed as the second element.
165
+ #
166
+ # @return [Hash<String, Array<Fixnum>>] Stats about the aliens encountered
57
167
  def alien_stats
58
168
  return unless public?
59
169
 
@@ -74,7 +184,7 @@ class DefenseGridStats < GameStats
74
184
  @alien_stats
75
185
  end
76
186
 
77
- # Returns stats about the towers built
187
+ # Returns stats about the towers built by the player
78
188
  #
79
189
  # The Hash returned uses the names of the towers as keys. Every value of
80
190
  # the Hash is another Hash using the keys 1 to 3 for different tower levels.
@@ -84,6 +194,8 @@ class DefenseGridStats < GameStats
84
194
  #
85
195
  # The Command tower uses the resources gained as second element.
86
196
  # The Temporal tower doesn't have a second element.
197
+ #
198
+ # @return [Hash<String, Array<Fixnum>>] Stats about the towers built
87
199
  def tower_stats
88
200
  return unless public?
89
201
 
@@ -1,20 +1,76 @@
1
- # This code is free software; you can redistribute it and/or modify it under the
2
- # terms of the new BSD License.
1
+ # This code is free software; you can redistribute it and/or modify it under
2
+ # the terms of the new BSD License.
3
3
  #
4
- # Copyright (c) 2009-2010, Sebastian Staudt
4
+ # Copyright (c) 2009-2011, Sebastian Staudt
5
5
 
6
6
  require 'steam/community/game_class'
7
7
 
8
- # Represents the stats for a DoD:S class for a specific user
8
+ # Represents the stats for a Day of Defeat: Source class for a specific user
9
+ #
10
+ # @author Sebastian Staudt
9
11
  class DoDSClass
10
12
 
11
13
  include GameClass
12
14
 
13
- attr_reader :blocks, :bombs_defused, :bombs_planted, :captures, :deaths,
14
- :dominations, :key, :kills, :name, :rounds_lost, :rounds_won,
15
- :revenges
15
+ # Returns the blocks achieved by the player with this class
16
+ #
17
+ # @return [Fixnum] The blocks achieved by the player
18
+ attr_reader :blocks
19
+
20
+ # Returns the bombs defused by the player with this class
21
+ #
22
+ # @return [Fixnum] The bombs defused by the player
23
+ attr_reader :bombs_defused
24
+
25
+ # Returns the bombs planted by the player with this class
26
+ #
27
+ # @return [Fixnum] the bombs planted by the player
28
+ attr_reader :bombs_planted
29
+
30
+ # Returns the number of points captured by the player with this class
31
+ #
32
+ # @return [Fixnum] The number of points captured by the player
33
+ attr_reader :captures
34
+
35
+ # Returns the number of times the player died with this class
36
+ #
37
+ # @return [Fixnum] The number of deaths by the player
38
+ attr_reader :deaths
39
+
40
+ # Returns the dominations achieved by the player with this class
41
+ #
42
+ # @return [Fixnum] The dominations achieved by the player
43
+ attr_reader :dominations
44
+
45
+ # Returns the ID of this class
46
+ #
47
+ # @return [String] The ID of this class
48
+ attr_reader :key
49
+
50
+ # Returns the number of enemies killed by the player with this class
51
+ #
52
+ # @return [Fixnum] The number of enemies killed by the player
53
+ attr_reader :kills
54
+
55
+ # Returns the number of rounds lost with this class
56
+ #
57
+ # @return [Fixnum] The number of rounds lost with this class
58
+ attr_reader :rounds_lost
59
+
60
+ # Returns the revenges achieved by the player with this class
61
+ #
62
+ # @return [Fixnum] The revenges achieved by the player
63
+ attr_reader :revenges
64
+
65
+ # Returns the number of rounds won with this class
66
+ #
67
+ # @return [Fixnum] The number of rounds won with this class
68
+ attr_reader :rounds_won
16
69
 
17
- # Creates a new instance of DoDSClass based on the assigned XML data
70
+ # Creates a new instance of a Day of Defeat: Source class based on the given
71
+ # XML data
72
+ #
73
+ # @param [REXML::Element] class_data The XML data of the class
18
74
  def initialize(class_data)
19
75
  @blocks = class_data.elements['blocks'].text.to_i
20
76
  @bombs_defused = class_data.elements['bombsdefused'].text.to_i
@@ -24,8 +80,8 @@ class DoDSClass
24
80
  @dominations = class_data.elements['dominations'].text.to_i
25
81
  @key = class_data.attributes['key']
26
82
  @kills = class_data.elements['kills'].text.to_i
27
- @name = class_data.elements["name"].text
28
- @play_time = class_data.elements["playtime"].text.to_i
83
+ @name = class_data.elements['name'].text
84
+ @play_time = class_data.elements['playtime'].text.to_i
29
85
  @rounds_lost = class_data.elements['roundslost'].text.to_i
30
86
  @rounds_won = class_data.elements['roundswon'].text.to_i
31
87
  @revenges = class_data.elements['revenges'].text.to_i
@@ -1,21 +1,31 @@
1
- # This code is free software; you can redistribute it and/or modify it under the
2
- # terms of the new BSD License.
1
+ # This code is free software; you can redistribute it and/or modify it under
2
+ # the terms of the new BSD License.
3
3
  #
4
- # Copyright (c) 2009-2010, Sebastian Staudt
4
+ # Copyright (c) 2009-2011, Sebastian Staudt
5
5
 
6
6
  require 'steam/community/dods/dods_weapon'
7
7
  require 'steam/community/game_stats'
8
8
 
9
+ # The is class represents the game statistics for a single user in Day of
10
+ # Defeat: Source
11
+ #
12
+ # @author Sebastian Staudt
9
13
  class DoDSStats < GameStats
10
14
 
11
- # Creates a DoDSStats object by calling the super constructor with the game
12
- # name "DoD:S"
15
+ # Creates a `DoDSStats` instance by calling the super constructor with the
16
+ # game name `'DoD:S'`
17
+ #
18
+ # @param [String, Fixnum] steam_id The custom URL or 64bit Steam ID of the
19
+ # user
13
20
  def initialize(steam_id)
14
21
  super steam_id, 'DoD:S'
15
22
  end
16
23
 
17
- # Returns a Hash of DoDSClass for this user containing all DoD:S classes.
24
+ # Returns a hash of `DoDSClass` for this user containing all DoD:S classes.
25
+ #
18
26
  # If the classes haven't been parsed already, parsing is done now.
27
+ #
28
+ # @return [Hash<String, DoDSClass>] The class statistics for this user
19
29
  def class_stats
20
30
  return unless public?
21
31
 
@@ -29,8 +39,11 @@ class DoDSStats < GameStats
29
39
  @class_stats
30
40
  end
31
41
 
32
- # Returns a Hash of DoDSWeapon for this user containing all DoD:S weapons.
42
+ # Returns a Hash of `DoDSWeapon` for this user containing all DoD:S weapons.
43
+ #
33
44
  # If the weapons haven't been parsed already, parsing is done now.
45
+ #
46
+ # @return [Hash<String, DoDSWeapon>] The weapon statistics for this user
34
47
  def weapon_stats
35
48
  return unless public?
36
49
 
@@ -1,18 +1,36 @@
1
- # This code is free software; you can redistribute it and/or modify it under the
2
- # terms of the new BSD License.
1
+ # This code is free software; you can redistribute it and/or modify it under
2
+ # the terms of the new BSD License.
3
3
  #
4
- # Copyright (c) 2009-2010, Sebastian Staudt
4
+ # Copyright (c) 2009-2011, Sebastian Staudt
5
5
 
6
6
  require 'steam/community/game_weapon'
7
7
 
8
8
  # Represents the stats for a Day of Defeat: Source weapon for a specific user
9
+ #
10
+ # @author Sebastian Staudt
9
11
  class DoDSWeapon
10
12
 
11
13
  include GameWeapon
12
14
 
13
- attr_reader :headshots, :name, :hits
15
+ # Returns the number of headshots achieved with this weapon
16
+ #
17
+ # @return [Fixnum] The number of headshots achieved
18
+ attr_reader :headshots
19
+
20
+ # Returns the name of this weapon
21
+ #
22
+ # @return [String] The name of this weapon
23
+ attr_reader :name
24
+
25
+ # Returns the number of hits achieved with this weapon
26
+ #
27
+ # @return [Fixnum] The number of hits achieved
28
+ attr_reader :hits
14
29
 
15
- # Creates a new instance of DoDSWeapon based on the assigned XML data
30
+ # Creates a new instance of a Day of Defeat: Source weapon based on the
31
+ # given XML data
32
+ #
33
+ # @param [REXML::Element] weapon_data The XML data of the class
16
34
  def initialize(weapon_data)
17
35
  super weapon_data
18
36
 
@@ -23,34 +41,27 @@ class DoDSWeapon
23
41
  @hits = weapon_data.elements['shotshit'].text.to_i
24
42
  end
25
43
 
26
- # Returns the average number of hits needed for a kill with this weapon.
27
- # Calculates the value if needed.
44
+ # Returns the average number of hits needed for a kill with this weapon
45
+ #
46
+ # @return [Float] The average number of hits needed for a kill
28
47
  def avg_hits_per_kill
29
- if @avg_hits_per_kill.nil?
30
- @avg_hits_per_kill = @hits.to_f / @kills
31
- end
32
-
33
- @avg_hits_per_kill
48
+ @hits.to_f / @kill
34
49
  end
35
50
 
36
51
  # Returns the percentage of headshots relative to the shots hit with this
37
- # weapon. Calculates the value if needed.
52
+ # weapon
53
+ #
54
+ # @return [Float] The percentage of headshots
38
55
  def headshot_percentage
39
- if @headshot_percentage.nil?
40
- @headshot_percentage = @headshots.to_f / @hits
41
- end
42
-
43
- @headshot_percentage
56
+ @headshots.to_f / @hits
44
57
  end
45
58
 
46
59
  # Returns the percentage of hits relative to the shots fired with this
47
- # weapon. Calculates the value if needed.
60
+ # weapon
61
+ #
62
+ # @return [Float] The percentage of hits
48
63
  def hit_percentage
49
- if @hit_percentage.nil?
50
- @hit_percentage = @hits.to_f / @shots
51
- end
52
-
53
- @hit_percentage
64
+ @hits.to_f / @shots
54
65
  end
55
66
 
56
67
  end