Class: SteamCondenser::Community::GameAchievement

Inherits:
Object
  • Object
show all
Defined in:
lib/steam-condenser/community/game_achievement.rb

Overview

The GameAchievement class represents a specific achievement for a single game and for a single user

It also provides the ability to load the global unlock percentages of all achievements of a specific game.

Author:

  • Sebastian Staudt

Defined Under Namespace

Classes: Instance

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(schema, data) ⇒ GameAchievement

Creates the achievement with the given name for the given user and game and achievement data

Parameters:

  • schema (GameStatsSchema)

    The game this achievement belongs to

  • data (Hash<String, Object>)

    The achievement data extracted from the game schema


71
72
73
74
75
76
77
# File 'lib/steam-condenser/community/game_achievement.rb', line 71

def initialize(schema, data)
  @api_name        = data[:name]
  @schema          = schema
  @hidden          = data[:hidden] == 1
  @icon_closed_url = data[:icon]
  @icon_open_url   = data[:icongray]
end

Instance Attribute Details

#api_nameString (readonly)

Returns the symbolic API name of this achievement

Returns:

  • (String)

     The API name of this achievement


24
25
26
# File 'lib/steam-condenser/community/game_achievement.rb', line 24

def api_name
  @api_name
end

#hiddenObject (readonly)

Returns the value of attribute hidden


26
27
28
# File 'lib/steam-condenser/community/game_achievement.rb', line 26

def hidden
  @hidden
end

#icon_closed_urlString (readonly)

Returns the url for the closed icon of this achievement

Returns:

  • (String)

    The url of the closed achievement icon


31
32
33
# File 'lib/steam-condenser/community/game_achievement.rb', line 31

def icon_closed_url
  @icon_closed_url
end

#icon_open_urlString (readonly)

Returns the url for the open icon of this achievement

Returns:

  • (String)

    The url of the open achievement icon


36
37
38
# File 'lib/steam-condenser/community/game_achievement.rb', line 36

def icon_open_url
  @icon_open_url
end

#schemaGameStatsSchema (readonly)

Return the stats schema of the game this achievement belongs to

Returns:

  • (GameStatsSchema)

    The stats schema of game this achievement belongs to


42
43
44
# File 'lib/steam-condenser/community/game_achievement.rb', line 42

def schema
  @schema
end

Class Method Details

.global_percentages(app_id) ⇒ Hash<Symbol, Float>

Loads the global unlock percentages of all achievements for the game with the given Steam Application ID

Parameters:

Returns:

  • (Hash<Symbol, Float>)

    The symbolic achievement names with their corresponding unlock percentages

Raises:


54
55
56
57
58
59
60
61
62
63
# File 'lib/steam-condenser/community/game_achievement.rb', line 54

def self.global_percentages(app_id)
  percentages = {}

  data = WebApi.json('ISteamUserStats', 'GetGlobalAchievementPercentagesForApp', 2, { :gameid => app_id })
  data[:achievementpercentages][:achievements].each do |percentage|
    percentages[percentage[:name].to_sym] = percentage[:percent]
  end

  percentages
end

Instance Method Details

#description(language = GameStatsSchema.default_language) ⇒ String

Returns the description of this achievement

Parameters:

  • language (Symbol) (defaults to: GameStatsSchema.default_language)

Returns:

  • (String)

     The description of this achievement


83
84
85
# File 'lib/steam-condenser/community/game_achievement.rb', line 83

def description(language = GameStatsSchema.default_language)
  @schema.achievement_translations(language)[@api_name][:description]
end

#inspectObject


87
88
89
# File 'lib/steam-condenser/community/game_achievement.rb', line 87

def inspect
  "#<#{self.class}:#@api_name>"
end

#instance(user, unlocked) ⇒ Object


91
92
93
# File 'lib/steam-condenser/community/game_achievement.rb', line 91

def instance(user, unlocked)
  Instance.new self, user, unlocked
end

#name(language = GameStatsSchema.default_language) ⇒ String

Returns the name of this achievement

Parameters:

  • language (Symbol) (defaults to: GameStatsSchema.default_language)

Returns:

  • (String)

     The name of this achievement


99
100
101
# File 'lib/steam-condenser/community/game_achievement.rb', line 99

def name(language = GameStatsSchema.default_language)
  @schema.achievement_translations(language)[@api_name][:name]
end