Class: TF2Stats
- Defined in:
- lib/steam/community/tf2/tf2_stats.rb
Overview
This class represents the game statistics for a single user in Team Fortress 2
Instance Attribute Summary collapse
-
#accumulated_points ⇒ Fixnum
readonly
Returns the total points this player has achieved in his career.
-
#total_playtime ⇒ Fixnum
readonly
Returns the accumulated number of seconds this player has spent playing as a TF2 class.
Attributes inherited from GameStats
#game, #hours_played, #privacy_state, #user
Instance Method Summary collapse
-
#class_stats ⇒ Hash<String, TF2Class>
Returns the statistics for all Team Fortress 2 classes for this user.
-
#initialize(steam_id, beta, fetch = true, bypass_cache = false) ⇒ TF2Stats
constructor
Creates a ‘TF2Stats` instance by calling the super constructor with the game name `’tf2’‘.
-
#inventory ⇒ TF2Inventory
Returns the current Team Fortress 2 inventory (a.k.a. backpack) of this player.
Methods inherited from GameStats
#achievements, #achievements_done, #achievements_percentage, base_url, #base_url, create_game_stats, #public?
Methods included from XMLData
Constructor Details
#initialize(steam_id, beta, fetch = true, bypass_cache = false) ⇒ TF2Stats
Creates a ‘TF2Stats` instance by calling the super constructor with the game name `’tf2’‘
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/steam/community/tf2/tf2_stats.rb', line 34 def initialize(steam_id, beta = false) super steam_id, (beta ? '520' : 'tf2') if public? && !@xml_data['stats']['accumulatedPoints'].nil? @accumulated_points = @xml_data['stats']['accumulatedPoints'].to_i end if public? && !@xml_data['stats']['secondsPlayedAllClassesLifetime'].nil? @total_playtime = @xml_data['stats']['secondsPlayedAllClassesLifetime'] end end |
Instance Attribute Details
#accumulated_points ⇒ Fixnum (readonly)
Returns the total points this player has achieved in his career
20 21 22 |
# File 'lib/steam/community/tf2/tf2_stats.rb', line 20 def accumulated_points @accumulated_points end |
#total_playtime ⇒ Fixnum (readonly)
Returns the accumulated number of seconds this player has spent playing as a TF2 class
25 26 27 |
# File 'lib/steam/community/tf2/tf2_stats.rb', line 25 def total_playtime @total_playtime end |
Instance Method Details
#class_stats ⇒ Hash<String, TF2Class>
Returns the statistics for all Team Fortress 2 classes for this user
If the classes haven’t been parsed already, parsing is done now.
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/steam/community/tf2/tf2_stats.rb', line 51 def class_stats return unless public? if @class_stats.nil? @class_stats = Hash.new @xml_data['stats']['classData'].each do |class_data| @class_stats[class_data['className']] = TF2ClassFactory.tf2_class(class_data) end end @class_stats end |
#inventory ⇒ TF2Inventory
Returns the current Team Fortress 2 inventory (a.k.a. backpack) of this player
68 69 70 71 72 73 74 75 |
# File 'lib/steam/community/tf2/tf2_stats.rb', line 68 def inventory if @inventory.nil? inventory_class = (game.short_name == 'tf2') ? TF2Inventory : TF2BetaInventory @inventory = inventory_class.new(user.steam_id64) if @inventory.nil? end @inventory end |