Class: GameItemSchema
- Inherits:
-
Object
- Object
- GameItemSchema
- Includes:
- Cacheable
- Defined in:
- lib/steam/community/game_item_schema.rb
Overview
Provides item definitions and related data that specify the items of a game
Instance Attribute Summary collapse
-
#app_id ⇒ Fixnum
readonly
Returns the application ID of the game this item schema belongs to.
-
#attributes ⇒ Hash<Symbol, Object>
readonly
The attributes defined for this game’s items.
-
#effects ⇒ Hash<Symbol, Object>
readonly
The effects defined for this game’s items.
-
#item_levels ⇒ Hash<Symbol, Object>
readonly
The levels defined for this game’s items.
-
#item_names ⇒ Hash<Symbol, Object>
readonly
A mapping from the item name to the item’s defindex.
-
#item_sets ⇒ Hash<Symbol, Object>
readonly
The item sets defined for this game’s items.
-
#items ⇒ Hash<Symbol, Object>
readonly
The items defined for this game.
-
#language ⇒ Symbol
readonly
The language of this item schema.
-
#origins ⇒ Array<String>
readonly
The item origins defined for this game’s items.
-
#qualities ⇒ Array<String>
readonly
The item qualities defined for this game’s items.
Attributes included from Cacheable
Instance Method Summary collapse
-
#fetch ⇒ Object
Updates the item definitions of this schema using the Steam Web API.
-
#initialize(app_id, language, fetch = true, bypass_cache = false) ⇒ GameItemSchema
constructor
Creates a new item schema for the game with the given application ID and with descriptions in the given language.
-
#inspect ⇒ String
Returns a short, human-readable string representation of this item schema.
Methods included from Cacheable
Constructor Details
#initialize(app_id, language, fetch = true, bypass_cache = false) ⇒ GameItemSchema
Creates a new item schema for the game with the given application ID and with descriptions in the given language
72 73 74 75 |
# File 'lib/steam/community/game_item_schema.rb', line 72 def initialize(app_id, language = nil) @app_id = app_id @language = language end |
Instance Attribute Details
#app_id ⇒ Fixnum (readonly)
Returns the application ID of the game this item schema belongs to
19 20 21 |
# File 'lib/steam/community/game_item_schema.rb', line 19 def app_id @app_id end |
#attributes ⇒ Hash<Symbol, Object> (readonly)
The attributes defined for this game’s items
24 25 26 |
# File 'lib/steam/community/game_item_schema.rb', line 24 def attributes @attributes end |
#effects ⇒ Hash<Symbol, Object> (readonly)
The effects defined for this game’s items
29 30 31 |
# File 'lib/steam/community/game_item_schema.rb', line 29 def effects @effects end |
#item_levels ⇒ Hash<Symbol, Object> (readonly)
The levels defined for this game’s items
34 35 36 |
# File 'lib/steam/community/game_item_schema.rb', line 34 def item_levels @item_levels end |
#item_names ⇒ Hash<Symbol, Object> (readonly)
A mapping from the item name to the item’s defindex
39 40 41 |
# File 'lib/steam/community/game_item_schema.rb', line 39 def item_names @item_names end |
#item_sets ⇒ Hash<Symbol, Object> (readonly)
The item sets defined for this game’s items
44 45 46 |
# File 'lib/steam/community/game_item_schema.rb', line 44 def item_sets @item_sets end |
#items ⇒ Hash<Symbol, Object> (readonly)
The items defined for this game
49 50 51 |
# File 'lib/steam/community/game_item_schema.rb', line 49 def items @items end |
#language ⇒ Symbol (readonly)
The language of this item schema
54 55 56 |
# File 'lib/steam/community/game_item_schema.rb', line 54 def language @language end |
#origins ⇒ Array<String> (readonly)
The item origins defined for this game’s items
59 60 61 |
# File 'lib/steam/community/game_item_schema.rb', line 59 def origins @origins end |
#qualities ⇒ Array<String> (readonly)
The item qualities defined for this game’s items
64 65 66 |
# File 'lib/steam/community/game_item_schema.rb', line 64 def qualities @qualities end |
Instance Method Details
#fetch ⇒ Object
Updates the item definitions of this schema using the Steam Web API
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/steam/community/game_item_schema.rb', line 78 def fetch params = { :language => language } data = WebApi.json!("IEconItems_#{app_id}", 'GetSchema', 1, params) @attributes = {} data[:attributes].each do |attribute| @attributes[attribute[:defindex]] = attribute @attributes[attribute[:name]] = attribute end @effects = {} data[:attribute_controlled_attached_particles].each do |effect| @effects[effect[:id]] = effect[:name] end @items = {} @item_names = {} data[:items].each do |item| @items[item[:defindex]] = item @item_names[item[:name]] = item[:defindex] end @item_levels = {} data[:item_levels].each do |item_level_type| @item_levels[item_level_type[:name]] = {} item_level_type[:levels].each do |level| @item_levels[item_level_type[:name]][level[:level]] = level[:name] end end if data.key? :item_levels @item_sets = {} data[:item_sets].each do |item_set| @item_sets[item_set[:item_set]] = item_set end @origins = [] data[:originNames].each do |origin| @origins[origin[:origin]] = origin[:name] end @qualities = [] data[:qualities].keys.each_with_index do |key, index| @qualities[index] = data[:qualityNames][key] || key.to_s.capitalize end end |
#inspect ⇒ String
Returns a short, human-readable string representation of this item schema
127 128 129 |
# File 'lib/steam/community/game_item_schema.rb', line 127 def inspect "#<#{self.class}:#@app_id (#@language) - #{fetch_time || 'not fetched'}>" end |