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

#game, #hours_played, #privacy_state, #user

Instance Method Summary collapse

Methods inherited from GameStats

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

Methods included from XMLData

#parse

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’‘

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

  • fetch (Boolean)

    if ‘true` the object’s data is fetched after creation

  • bypass_cache (Boolean)

    if ‘true` the object’s data is fetched again even if it has been cached already



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_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

#total_playtimeFixnum (readonly)

Returns the accumulated number of seconds this player has spent playing as a TF2 class

Returns:

  • (Fixnum)

    total seconds played 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_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



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

#inventoryTF2Inventory

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

Returns:



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