Class: L4D2Map

Inherits:
L4DMap show all
Defined in:
lib/steam/community/l4d/l4d2_map.rb

Overview

L4D2Map holds statistical information about maps played by a player in Survival mode of Left4Dead 2. The basic information provided is more or less the same for Left4Dead and Left4Dead 2, but parsing has to be done differently.

Constant Summary collapse

INFECTED =
%w{boomer charger common hunter jockey smoker spitter tank}
ITEMS =
%w{adrenaline defibs medkits pills}

Constants inherited from L4DMap

L4DMap::BRONZE, L4DMap::GOLD, L4DMap::NONE, L4DMap::SILVER

Instance Attribute Summary collapse

Attributes inherited from L4DMap

#best_time, #id, #medal, #name, #times_played

Instance Method Summary collapse

Constructor Details

#initialize(map_data) ⇒ L4D2Map

Creates a new instance of L4D2Map based on the assigned XML data

The map statistics for the Survival mode of Left4Dead 2 hold much more information than those for Left4Dead, e.g. the teammates and items are listed.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/steam/community/l4d/l4d2_map.rb', line 25

def initialize(map_data)
  @id        = map_data.elements['img'].text.match(/http:\/\/steamcommunity\.com\/public\/images\/gamestats\/550\/(.*).jpg/)[1]
  @name      = map_data.elements['name'].text
  @played    = (map_data.elements['hasPlayed'].text.to_i == 1)

  if @played
    @best_time = map_data.elements['besttimemilliseconds'].text.to_f / 1000

    @teammates = []
    map_data.elements.each('teammates/steamID64') do |teammate|
      @teammates << SteamId.new(teammate.text, false)
    end

    @items = {}
    ITEMS.each do |item|
      @items[item] = map_data.elements["items_#{item}"].text.to_i
    end

    @kills = {}
    INFECTED.each do |infected|
      @kills[infected] = map_data.elements["kills_#{infected}"].text.to_i
    end

    case map_data.elements['medal'].text
      when 'gold'
        @medal = L4D2Map::GOLD
      when 'silver'
        @medal = L4D2Map::SILVER
      when 'bronze'
        @medal = L4D2Map::BRONZE
      else
        @medal = L4D2Map::NONE
    end
  end
end

Instance Attribute Details

#itemsObject (readonly)

Returns the value of attribute items.



15
16
17
# File 'lib/steam/community/l4d/l4d2_map.rb', line 15

def items
  @items
end

#killsObject (readonly)

Returns the value of attribute kills.



15
16
17
# File 'lib/steam/community/l4d/l4d2_map.rb', line 15

def kills
  @kills
end

#teammatesObject (readonly)

Returns the value of attribute teammates.



15
16
17
# File 'lib/steam/community/l4d/l4d2_map.rb', line 15

def teammates
  @teammates
end

Instance Method Details

#played?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/steam/community/l4d/l4d2_map.rb', line 61

def played?
  @played
end