Class: TF2Stats

Inherits:
GameStats show all
Defined in:
lib/steam/community/tf2/tf2_stats.rb

Overview

This class represents the game statistics for a single user in Team Fortress 2

Author:

  • Sebastian Staudt

Instance Attribute Summary collapse

Attributes inherited from GameStats

#app_id, #custom_url, #game_friendly_name, #game_name, #hours_played, #privacy_state, #steam_id64

Instance Method Summary collapse

Methods inherited from GameStats

#achievements, #achievements_done, #achievements_percentage, #base_url, create_game_stats, #leaderboard, #leaderboards, #public?

Constructor Details

#initialize(steam_id, beta = false) ⇒ TF2Stats

Creates a ‘TF2Stats` instance by calling the super constructor with the game name `’tf2’‘

Parameters:

  • steam_id (String, Fixnum)

    The custom URL or 64bit Steam ID of the user

  • beta (Boolean) (defaults to: false)

    If ‘true, creates stats for the public TF2 beta



28
29
30
31
32
33
34
# File 'lib/steam/community/tf2/tf2_stats.rb', line 28

def initialize(steam_id, beta = false)
  super steam_id, (beta ? '520' : 'tf2')

  if public? && !@xml_data.elements['stats/accumulatedPoints'].nil?
    @accumulated_points = @xml_data.elements['stats/accumulatedPoints'].text.to_i
  end
end

Instance Attribute Details

#accumulated_pointsFixnum (readonly)

Returns the total points this player has achieved in his career

Returns:

  • (Fixnum)

    This player’s accumulated points



20
21
22
# File 'lib/steam/community/tf2/tf2_stats.rb', line 20

def accumulated_points
  @accumulated_points
end

Instance Method Details

#class_statsHash<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.

Returns:

  • (Hash<String, TF2Class>)

    A hash storing individual stats for each Team Fortress 2 class



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/steam/community/tf2/tf2_stats.rb', line 42

def class_stats
  return unless public?

  if @class_stats.nil?
    @class_stats = Hash.new
    @xml_data.elements.each('stats/classData') do |class_data|
      @class_stats[class_data.elements['className'].text] = TF2ClassFactory.tf2_class(class_data)
    end
  end

  @class_stats
end

#inventoryTF2Inventory

Returns the current Team Fortress 2 inventory (a.k.a. backpack) of this player

Returns:



59
60
61
62
63
64
65
66
# File 'lib/steam/community/tf2/tf2_stats.rb', line 59

def inventory
  if @inventory.nil?
    inventory_class = (game_friendly_name == 'tf2') ? TF2Inventory : TF2BetaInventory
    @inventory = inventory_class.new(steam_id64) if @inventory.nil?
  end

  @inventory
end