Module: AbstractL4DStats
Overview
This module is a base for statistics for Left4Dead and Left4Dead 2. As both games have more or less the same statistics available in the Steam Community the code for both is pretty much the same.
Constant Summary collapse
- SPECIAL_INFECTED =
The names of the special infected in Left4Dead
%w(boomer hunter smoker tank)
Instance Attribute Summary collapse
-
#most_recent_game ⇒ Hash<String, Object>
readonly
Returns a hash of statistics for this user’s most recently played game.
Instance Method Summary collapse
-
#favorites ⇒ Hash<String, Object>
Returns a hash of favorites for this user like weapons and character.
-
#initialize(steam_id, game_name) ⇒ Object
Creates a new instance of statistics for both, Left4Dead and Left4Dead 2 parsing basic common data.
-
#lifetime_stats ⇒ Hash<String, Object>
Returns a hash of lifetime statistics for this user like the time played.
-
#survival_stats ⇒ Hash<String, Object>
Returns a hash of Survival statistics for this user like revived teammates.
-
#teamplay_stats ⇒ Hash<String, Object>
Returns a hash of teamplay statistics for this user like revived teammates.
-
#versus_stats ⇒ Hash<String, Object>
Returns a hash of Versus statistics for this user like percentage of rounds won.
Instance Attribute Details
#most_recent_game ⇒ Hash<String, Object> (readonly)
Returns a hash of statistics for this user’s most recently played game
21 22 23 |
# File 'lib/steam/community/l4d/abstract_l4d_stats.rb', line 21 def most_recent_game @most_recent_game end |
Instance Method Details
#favorites ⇒ Hash<String, Object>
Returns a hash of favorites for this user like weapons and character
If the favorites haven’t been parsed already, parsing is done now.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/steam/community/l4d/abstract_l4d_stats.rb', line 47 def favorites return unless public? if @favorites.nil? @favorites = {} @favorites[:campaign] = @xml_data['stats']['favorites']['campaign'] @favorites[:campaign_percentage] = @xml_data['stats']['favorites']['campaignpct'].to_i @favorites[:character] = @xml_data['stats']['favorites']['character'] @favorites[:character_percentage] = @xml_data['stats']['favorites']['characterpct'].to_i @favorites[:level1_weapon] = @xml_data['stats']['favorites']['weapon1'] @favorites[:level1_weapon_percentage] = @xml_data['stats']['favorites']['weapon1pct'].to_i @favorites[:level2_weapon] = @xml_data['stats']['favorites']['weapon2'] @favorites[:level2_weapon_percentage] = @xml_data['stats']['favorites']['weapon2pct'].to_i end @favorites end |
#initialize(steam_id, game_name) ⇒ Object
Creates a new instance of statistics for both, Left4Dead and Left4Dead 2 parsing basic common data
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/steam/community/l4d/abstract_l4d_stats.rb', line 28 def initialize(steam_id, game_name) super steam_id, game_name if public? @most_recent_game = {} unless @xml_data['stats']['mostrecentgame'].nil? @most_recent_game[:difficulty] = @xml_data['stats']['mostrecentgame']['difficulty'] @most_recent_game[:escaped] = (@xml_data['stats']['mostrecentgame']['bEscaped'] == 1) @most_recent_game[:movie] = @xml_data['stats']['mostrecentgame']['movie'] @most_recent_game[:time_played] = @xml_data['stats']['mostrecentgame']['time'] end end end |
#lifetime_stats ⇒ Hash<String, Object>
Returns a hash of lifetime statistics for this user like the time played
If the lifetime statistics haven’t been parsed already, parsing is done now.
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/steam/community/l4d/abstract_l4d_stats.rb', line 71 def lifetime_stats return unless public? if @lifetime_stats.nil? @lifetime_stats = {} @lifetime_stats[:finales_survived] = @xml_data['stats']['lifetime']['finales'].to_i @lifetime_stats[:games_played] = @xml_data['stats']['lifetime']['gamesplayed'].to_i @lifetime_stats[:infected_killed] = @xml_data['stats']['lifetime']['infectedkilled'].to_i @lifetime_stats[:kills_per_hour] = @xml_data['stats']['lifetime']['killsperhour'].to_f @lifetime_stats[:avg_kits_shared] = @xml_data['stats']['lifetime']['kitsshared'].to_f @lifetime_stats[:avg_kits_used] = @xml_data['stats']['lifetime']['kitsused'].to_f @lifetime_stats[:avg_pills_shared] = @xml_data['stats']['lifetime']['pillsshared'].to_f @lifetime_stats[:avg_pills_used] = @xml_data['stats']['lifetime']['pillsused'].to_f @lifetime_stats[:time_played] = @xml_data['stats']['lifetime']['timeplayed'] @lifetime_stats[:finales_survived_percentage] = @lifetime_stats[:finales_survived].to_f / @lifetime_stats[:games_played] end @lifetime_stats end |
#survival_stats ⇒ Hash<String, Object>
Returns a hash of Survival statistics for this user like revived teammates
If the Survival statistics haven’t been parsed already, parsing is done now.
98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/steam/community/l4d/abstract_l4d_stats.rb', line 98 def survival_stats return unless public? if @survival_stats.nil? @survival_stats = {} @survival_stats[:gold_medals] = @xml_data['stats']['survival']['goldmedals'].to_i @survival_stats[:silver_medals] = @xml_data['stats']['survival']['silvermedals'].to_i @survival_stats[:bronze_medals] = @xml_data['stats']['survival']['bronzemedals'].to_i @survival_stats[:rounds_played] = @xml_data['stats']['survival']['roundsplayed'].to_i @survival_stats[:best_time] = @xml_data['stats']['survival']['besttime'].to_f end @survival_stats end |
#teamplay_stats ⇒ Hash<String, Object>
Returns a hash of teamplay statistics for this user like revived teammates
If the teamplay statistics haven’t been parsed already, parsing is done now.
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/steam/community/l4d/abstract_l4d_stats.rb', line 119 def teamplay_stats return unless public? if @teamplay_stats.nil? @teamplay_stats = {} @teamplay_stats[:revived] = @xml_data['stats']['teamplay']['revived'].to_i @teamplay_stats[:most_revived_difficulty] = @xml_data['stats']['teamplay']['reviveddiff'] @teamplay_stats[:avg_revived] = @xml_data['stats']['teamplay']['revivedavg'].to_f @teamplay_stats[:avg_was_revived] = @xml_data['stats']['teamplay']['wasrevivedavg'].to_f @teamplay_stats[:protected] = @xml_data['stats']['teamplay']['protected'].to_i @teamplay_stats[:most_protected_difficulty] = @xml_data['stats']['teamplay']['protecteddiff'] @teamplay_stats[:avg_protected] = @xml_data['stats']['teamplay']['protectedavg'].to_f @teamplay_stats[:avg_was_protected] = @xml_data['stats']['teamplay']['wasprotectedavg'].to_f @teamplay_stats[:friendly_fire_damage] = @xml_data['stats']['teamplay']['ffdamage'].to_i @teamplay_stats[:most_friendly_fire_difficulty] = @xml_data['stats']['teamplay']['ffdamagediff'] @teamplay_stats[:avg_friendly_fire_damage] = @xml_data['stats']['teamplay']['ffdamageavg'].to_f end @teamplay_stats end |
#versus_stats ⇒ Hash<String, Object>
Returns a hash of Versus statistics for this user like percentage of rounds won
If the Versus statistics haven’t been parsed already, parsing is done now.
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/steam/community/l4d/abstract_l4d_stats.rb', line 146 def versus_stats return unless public? if @versus_stats.nil? @versus_stats = {} @versus_stats[:games_played] = @xml_data['stats']['versus']['gamesplayed'].to_i @versus_stats[:games_completed] = @xml_data['stats']['versus']['gamescompleted'].to_i @versus_stats[:finales_survived] = @xml_data['stats']['versus']['finales'].to_i @versus_stats[:points] = @xml_data['stats']['versus']['points'].to_i @versus_stats[:most_points_infected] = @xml_data['stats']['versus']['pointsas'] @versus_stats[:games_won] = @xml_data['stats']['versus']['gameswon'].to_i @versus_stats[:games_lost] = @xml_data['stats']['versus']['gameslost'].to_i @versus_stats[:highest_survivor_score] = @xml_data['stats']['versus']['survivorscore'].to_i @versus_stats[:finales_survived_percentage] = @versus_stats[:finales_survived].to_f / @versus_stats[:games_played] self.class.const_get(:SPECIAL_INFECTED).each do |infected| @versus_stats[infected] = {} @versus_stats[infected][:special_attacks] = @xml_data['stats']['versus']["#{infected}special"].to_i @versus_stats[infected][:most_damage] = @xml_data['stats']['versus']["#{infected}dmg"].to_i @versus_stats[infected]['avg_lifespan'] = @xml_data['stats']['versus']["#{infected}lifespan"].to_i end end @versus_stats end |