Class: L4DStats

Inherits:
GameStats show all
Includes:
AbstractL4DStats
Defined in:
lib/steam/community/l4d/l4d_stats.rb

Overview

This class represents the game statistics for a single user in Left4Dead

Author:

  • Sebastian Staudt

Constant Summary

Constants included from AbstractL4DStats

AbstractL4DStats::SPECIAL_INFECTED

Instance Attribute Summary

Attributes included from AbstractL4DStats

#most_recent_game

Attributes inherited from GameStats

#game, #hours_played, #privacy_state, #user

Instance Method Summary collapse

Methods included from AbstractL4DStats

#favorites, #lifetime_stats, #teamplay_stats, #versus_stats

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, fetch = true, bypass_cache = false) ⇒ L4DStats

Creates a ‘L4DStats` object by calling the super constructor with the game name `’l4d’‘

Parameters:

  • steam_id (String, Fixnum)

    The custom URL or 64bit Steam ID of the user

  • 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



24
25
26
# File 'lib/steam/community/l4d/l4d_stats.rb', line 24

def initialize(steam_id)
  super steam_id, 'l4d'
end

Instance Method Details

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

Returns:

  • (Hash<String, Object>)

    The stats for the Survival mode



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/steam/community/l4d/l4d_stats.rb', line 34

def survival_stats
  return unless public?

  if @survival_stats.nil?
    super
    @survival_stats[:maps] = {}
    @xml_data['stats']['survival']['maps'].each do |map_data|
      @survival_stats[:maps][map_data[0]] = L4DMap.new *map_data
    end
  end

  @survival_stats
end

#weapon_statsHash<String, Object>

Returns a hash of ‘L4DWeapon` for this user containing all Left4Dead weapons

If the weapons haven’t been parsed already, parsing is done now.

Returns:

  • (Hash<String, Object>)

    The weapon statistics



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/steam/community/l4d/l4d_stats.rb', line 54

def weapon_stats
  return unless public?

  if @weapon_stats.nil?
    @weapon_stats = {}
    @xml_data['stats']['weapons'].each do |weapon_data|
      unless %w{molotov pipes}.include? weapon_data[0]
        weapon = L4DWeapon.new *weapon_data
      else
        weapon = L4DExplosive.new *weapon_data
      end

      @weapon_stats[weapon_data[0]] = weapon
    end
  end

  @weapon_stats
end