Class: CSSMap

Inherits:
Object
  • Object
show all
Defined in:
lib/steam/community/css/css_map.rb

Overview

Represents the stats for a Counter-Strike: Source map for a specific user

Author:

  • Sebastian Staudt

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(map_name, maps_data) ⇒ CSSMap

Creates a new instance of a Counter-Strike: Source class based on the given XML data

Parameters:

  • map_name (String)

    The name of the map

  • maps_data (Hash<String, Object>)

    The XML data of all maps



36
37
38
39
40
41
42
43
44
45
# File 'lib/steam/community/css/css_map.rb', line 36

def initialize(map_name, maps_data)
  @name = map_name

  @favorite      = (maps_data['favorite'] == @name)
  @rounds_played = maps_data["#{@name}_rounds"].to_i
  @rounds_won    = maps_data["#{@name}_wins"].to_i

  @rounds_lost = @rounds_played - @rounds_won
  @rounds_won_percentage = (@rounds_played > 0) ? @rounds_won.to_f / @rounds_played : 0
end

Instance Attribute Details

#nameString (readonly)

Returns the name of this map

Returns:

  • (String)

    The name of this map



14
15
16
# File 'lib/steam/community/css/css_map.rb', line 14

def name
  @name
end

#rounds_lostFixnum (readonly)

Returns the number of rounds the player has lost on this map

Returns:

  • (Fixnum)

    The number of rounds lost



19
20
21
# File 'lib/steam/community/css/css_map.rb', line 19

def rounds_lost
  @rounds_lost
end

#rounds_playedFixnum (readonly)

Returns the number of rounds the player has played on this map

Returns:

  • (Fixnum)

    The number of rounds played



24
25
26
# File 'lib/steam/community/css/css_map.rb', line 24

def rounds_played
  @rounds_played
end

#rounds_wonFixnum (readonly)

Returns the number of rounds the player has won on this map

Returns:

  • (Fixnum)

    The number of rounds won



29
30
31
# File 'lib/steam/community/css/css_map.rb', line 29

def rounds_won
  @rounds_won
end

Instance Method Details

#favorite?Boolean

Returns whether this map is the favorite map of this player

Returns:

  • (Boolean)

    ‘true` if this is the favorite map



50
51
52
# File 'lib/steam/community/css/css_map.rb', line 50

def favorite?
  @favorite
end

#rounds_won_percentageFloat

Returns the percentage of rounds the player has won on this map

Returns:

  • (Float)

    The percentage of rounds won



57
58
59
# File 'lib/steam/community/css/css_map.rb', line 57

def rounds_won_percentage
  (@rounds_played > 0) ? @rounds_won.to_f / @rounds_played : 0
end