Class: GameLeaderboard
- Inherits:
-
Object
- Object
- GameLeaderboard
- Includes:
- XMLData
- Defined in:
- lib/steam/community/game_leaderboard.rb
Overview
The GameLeaderboard class represents a single leaderboard for a specific game
Constant Summary collapse
- DISPLAY_TYPE_NONE =
0
- DISPLAY_TYPE_NUMERIC =
1
- DISPLAY_TYPE_SECONDS =
2
- DISPLAY_TYPE_MILLISECONDS =
3
- SORT_METHOD_NONE =
0
- SORT_METHOD_ASC =
1
- SORT_METHOD_DESC =
2
- @@leaderboards =
{}
Instance Attribute Summary collapse
-
#display_type ⇒ Fixnum
readonly
Returns the display type of the scores on this leaderboard.
-
#entry_count ⇒ Fixnum
readonly
Returns the number of entries on this leaderboard.
-
#id ⇒ Fixnum
readonly
Returns the ID of the leaderboard.
-
#name ⇒ String
readonly
Returns the name of the leaderboard.
-
#sort_method ⇒ Fixnum
readonly
Returns the method that is used to sort the entries on the leaderboard.
Class Method Summary collapse
-
.leaderboard(game_name, id) ⇒ GameLeaderboard
Returns the leaderboard for the given game and leaderboard ID or name.
-
.leaderboards(game_name) ⇒ Array<GameLeaderboard>
Returns an array containing all of a game’s leaderboards.
Instance Method Summary collapse
-
#entry_for_steam_id(steam_id) ⇒ GameLeaderboardEntry
Returns the entry on this leaderboard for the user with the given SteamID.
-
#entry_for_steam_id_friends(steam_id) ⇒ Array<GameLeaderboardEntry>
Returns an array of entries on this leaderboard for the user with the given SteamID and his/her friends.
-
#entry_range(first, last) ⇒ Array<GameLeaderboardEntry>
Returns the entries on this leaderboard for a given rank range.
Methods included from XMLData
Instance Attribute Details
#display_type ⇒ Fixnum (readonly)
Returns the display type of the scores on this leaderboard
33 34 35 |
# File 'lib/steam/community/game_leaderboard.rb', line 33 def display_type @display_type end |
#entry_count ⇒ Fixnum (readonly)
Returns the number of entries on this leaderboard
38 39 40 |
# File 'lib/steam/community/game_leaderboard.rb', line 38 def entry_count @entry_count end |
#id ⇒ Fixnum (readonly)
Returns the ID of the leaderboard
43 44 45 |
# File 'lib/steam/community/game_leaderboard.rb', line 43 def id @id end |
#name ⇒ String (readonly)
Returns the name of the leaderboard
48 49 50 |
# File 'lib/steam/community/game_leaderboard.rb', line 48 def name @name end |
#sort_method ⇒ Fixnum (readonly)
Returns the method that is used to sort the entries on the leaderboard
53 54 55 |
# File 'lib/steam/community/game_leaderboard.rb', line 53 def sort_method @sort_method end |
Class Method Details
.leaderboard(game_name, id) ⇒ GameLeaderboard
Returns the leaderboard for the given game and leaderboard ID or name
60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/steam/community/game_leaderboard.rb', line 60 def self.leaderboard(game_name, id) leaderboards = self.leaderboards game_name if id.is_a? Fixnum leaderboards[id] else leaderboards.each_value do |board| return board if board.name == id end end end |
.leaderboards(game_name) ⇒ Array<GameLeaderboard>
Returns an array containing all of a game’s leaderboards
76 77 78 79 80 |
# File 'lib/steam/community/game_leaderboard.rb', line 76 def self.leaderboards(game_name) self.load_leaderboards game_name unless @@leaderboards.key? game_name @@leaderboards[game_name] end |
Instance Method Details
#entry_for_steam_id(steam_id) ⇒ GameLeaderboardEntry
Returns the entry on this leaderboard for the user with the given SteamID
raise [SteamCondenserException] if an error occurs while fetching the
leaderboard
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/steam/community/game_leaderboard.rb', line 89 def entry_for_steam_id(steam_id) steam_id = steam_id.steam_id64 if steam_id.is_a? SteamId parse "#@url&steamid=#{steam_id}" error = @xml_data['error'] raise SteamCondenserError, error unless error.nil? @xml_data['entries']['entry'].each do |entry_data| if entry_data['steamid'].to_i == steam_id return GameLeaderboardEntry.new entry_data, self end end nil end |
#entry_for_steam_id_friends(steam_id) ⇒ Array<GameLeaderboardEntry>
Returns an array of entries on this leaderboard for the user with the given SteamID and his/her friends
raise [SteamCondenserException] if an error occurs while fetching the
leaderboard
115 116 117 118 119 120 121 122 123 124 |
# File 'lib/steam/community/game_leaderboard.rb', line 115 def entry_for_steam_id_friends(steam_id) steam_id = steam_id.steam_id64 if steam_id.is_a? SteamId parse "#@url&steamid=#{steam_id}" error = @xml_data['error'] raise SteamCondenserError, error unless error.nil? parse_entries end |
#entry_range(first, last) ⇒ Array<GameLeaderboardEntry>
Returns the entries on this leaderboard for a given rank range
The range is inclusive and a maximum of 5001 entries can be returned in a single request.
raise [SteamCondenserException] if an error occurs while fetching the
leaderboard
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/steam/community/game_leaderboard.rb', line 137 def entry_range(first, last) if last < first raise SteamCondenserError, 'First entry must be prior to last entry for leaderboard entry lookup.' end if (last - first) > 5000 raise SteamCondenserError, 'Leaderboard entry lookup is currently limited to a maximum of 5001 entries per request.' end parse "#@url&start=#{first}&end=#{last}" error = @xml_data['error'] raise SteamCondenserError, error unless error.nil? entries = [] @xml_data['entries']['entry'].each do |entry_data| rank = entry_data['rank'].to_i entries[rank] = GameLeaderboardEntry.new entry_data, self end parse_entries end |