Class: SteamCondenser::Community::SteamGame
- Inherits:
-
Object
- Object
- SteamCondenser::Community::SteamGame
- Includes:
- Cacheable
- Defined in:
- lib/steam-condenser/community/steam_game.rb
Overview
This class represents a game available on Steam
Instance Attribute Summary collapse
-
#app_id ⇒ Fixnum
(also: #id)
readonly
Returns the Steam application ID of this game.
-
#name ⇒ String
readonly
Returns the full name of this game.
Attributes included from Cacheable
Class Method Summary collapse
-
.check_steam_inf(path) ⇒ Boolean
Checks if a game is up-to-date by reading information from a
steam.inf
file and comparing it using the Web API. -
.new(app_id, game_data = nil) ⇒ Object
Creates a new instance of a game with the given data and caches it.
-
.uptodate?(app_id, version) ⇒ Boolean
Returns whether the given version of the game with the given application ID is up-to-date.
Instance Method Summary collapse
-
#icon_url ⇒ String
Returns the URL for the icon image of this game.
-
#initialize(app_id, game_data) ⇒ SteamGame
constructor
private
Creates a new instance of a game with the given data and caches it.
-
#leaderboard(id) ⇒ GameLeaderboard
Returns the leaderboard for this game and the given leaderboard ID or name.
-
#leaderboards ⇒ Array<GameLeaderboard>
Returns an array containing all of this game's leaderboards.
-
#logo_thumbnail_url ⇒ String
Returns the URL for the logo thumbnail image of this game.
-
#logo_url ⇒ String
Returns the URL for the logo image of this game.
-
#player_count ⇒ Fixnum
Returns the overall number of players currently playing this game.
-
#store_url ⇒ String
Returns the URL of this game's page in the Steam Store.
-
#uptodate?(version) ⇒ Boolean
Returns whether the given version of this game is up-to-date.
-
#user_stats(steam_id) ⇒ GameStats
Creates a stats object for the given user and this game.
Methods included from Cacheable
#cache, #cache_id_value, #cache_ids, #cached_instance, #fetch, #fetched?, included
Constructor Details
#initialize(app_id, game_data) ⇒ SteamGame (private)
The real constructor of SteamGame
is new
Creates a new instance of a game with the given data and caches it
154 155 156 157 158 159 |
# File 'lib/steam-condenser/community/steam_game.rb', line 154 def initialize(app_id, game_data) @app_id = app_id @icon_hash = game_data[:img_icon_url] @logo_hash = game_data[:img_logo_url] @name = game_data[:name] end |
Instance Attribute Details
#app_id ⇒ Fixnum (readonly) Also known as: id
Returns the Steam application ID of this game
24 25 26 |
# File 'lib/steam-condenser/community/steam_game.rb', line 24 def app_id @app_id end |
#name ⇒ String (readonly)
Returns the full name of this game
30 31 32 |
# File 'lib/steam-condenser/community/steam_game.rb', line 30 def name @name end |
Class Method Details
.check_steam_inf(path) ⇒ Boolean
Checks if a game is up-to-date by reading information from a steam.inf
file and comparing it using the Web API
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/steam-condenser/community/steam_game.rb', line 37 def self.check_steam_inf(path) steam_inf = File.read path begin app_id = steam_inf.match(/^\s*appID=(\d+)\s*$/im)[1].to_i version = steam_inf.match(/^\s*PatchVersion=([\d\.]+)\s*$/im)[1].gsub('.', '').to_i rescue raise SteamCondenser::Error, "The steam.inf file at \"#{path}\" is invalid." end uptodate? app_id, version end |
.new(app_id, game_data = nil) ⇒ Object
Creates a new instance of a game with the given data and caches it
52 53 54 55 56 57 58 59 60 |
# File 'lib/steam-condenser/community/steam_game.rb', line 52 def self.new(app_id, game_data = nil) if cached? app_id class_variable_get(:@@cache)[app_id] else game = SteamGame.allocate game.send :initialize, app_id, game_data game end end |
.uptodate?(app_id, version) ⇒ Boolean
Returns whether the given version of the game with the given application ID is up-to-date
68 69 70 71 72 73 74 |
# File 'lib/steam-condenser/community/steam_game.rb', line 68 def self.uptodate?(app_id, version) params = { :appid => app_id, :version => version } result = WebApi.json 'ISteamApps', 'UpToDateCheck', 1, params result = result[:response] raise SteamCondenser::Error, result[:error] unless result[:success] result[:up_to_date] end |
Instance Method Details
#icon_url ⇒ String
Returns the URL for the icon image of this game
79 80 81 |
# File 'lib/steam-condenser/community/steam_game.rb', line 79 def icon_url "http://media.steampowered.com/steamcommunity/public/images/apps/#@app_id/#@icon_hash.jpg" end |
#leaderboard(id) ⇒ GameLeaderboard
Returns the leaderboard for this game and the given leaderboard ID or name
88 89 90 |
# File 'lib/steam-condenser/community/steam_game.rb', line 88 def leaderboard(id) GameLeaderboard.leaderboard @short_name, id end |
#leaderboards ⇒ Array<GameLeaderboard>
Returns an array containing all of this game's leaderboards
95 96 97 |
# File 'lib/steam-condenser/community/steam_game.rb', line 95 def leaderboards GameLeaderboard.leaderboards @short_name end |
#logo_thumbnail_url ⇒ String
Returns the URL for the logo thumbnail image of this game
109 110 111 |
# File 'lib/steam-condenser/community/steam_game.rb', line 109 def logo_thumbnail_url "http://media.steampowered.com/steamcommunity/public/images/apps/#@app_id/##{@logo_hash}_thumb.jpg" end |
#logo_url ⇒ String
Returns the URL for the logo image of this game
102 103 104 |
# File 'lib/steam-condenser/community/steam_game.rb', line 102 def logo_url "http://media.steampowered.com/steamcommunity/public/images/apps/#@app_id/#@logo_hash.jpg" end |
#player_count ⇒ Fixnum
Returns the overall number of players currently playing this game
116 117 118 119 120 |
# File 'lib/steam-condenser/community/steam_game.rb', line 116 def player_count params = { :appid => @app_id } result = WebApi.json 'ISteamUserStats', 'GetNumberOfCurrentPlayers', 1, params result[:response][:player_count] end |
#store_url ⇒ String
Returns the URL of this game's page in the Steam Store
125 126 127 |
# File 'lib/steam-condenser/community/steam_game.rb', line 125 def store_url "http://store.steampowered.com/app/#@app_id" end |
#uptodate?(version) ⇒ Boolean
Returns whether the given version of this game is up-to-date
133 134 135 |
# File 'lib/steam-condenser/community/steam_game.rb', line 133 def uptodate?(version) self.class.uptodate? @app_id, version end |
#user_stats(steam_id) ⇒ GameStats
Creates a stats object for the given user and this game
142 143 144 |
# File 'lib/steam-condenser/community/steam_game.rb', line 142 def user_stats(steam_id) GameStats.new steam_id, @app_id end |