Class: GameItemSchema

Inherits:
Object
  • Object
show all
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

Author:

  • Sebastian Staudt

Instance Attribute Summary collapse

Attributes included from Cacheable

#fetch_time

Instance Method Summary collapse

Methods included from Cacheable

#cache, #fetched?, included

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

Parameters:

  • app_id (Fixnum)

    The application ID of the game

  • language (Symbol) (defaults to: nil)

    The language of description strings

  • fetch (Boolean)

    if ‘true` the object’s data is fetched after creation

  • bypass_cache (Boolean)

    if ‘true` the object’s data is fetched again even if it has been cached already



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_idFixnum (readonly)

Returns the application ID of the game this item schema belongs to

Returns:

  • (Fixnum)

    The application ID of the game



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

def app_id
  @app_id
end

#attributesHash<Symbol, Object> (readonly)

The attributes defined for this game’s items

Returns:

  • (Hash<Symbol, Object>)

    This item schema’s attributes



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

def attributes
  @attributes
end

#effectsHash<Symbol, Object> (readonly)

The effects defined for this game’s items

Returns:

  • (Hash<Symbol, Object>)

    This item schema’s effects



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

def effects
  @effects
end

#item_levelsHash<Symbol, Object> (readonly)

The levels defined for this game’s items

Returns:

  • (Hash<Symbol, Object>)

    This item schema’s item levels



34
35
36
# File 'lib/steam/community/game_item_schema.rb', line 34

def item_levels
  @item_levels
end

#item_namesHash<Symbol, Object> (readonly)

A mapping from the item name to the item’s defindex

Returns:

  • (Hash<Symbol, Object>)

    The item name mapping



39
40
41
# File 'lib/steam/community/game_item_schema.rb', line 39

def item_names
  @item_names
end

#item_setsHash<Symbol, Object> (readonly)

The item sets defined for this game’s items

Returns:

  • (Hash<Symbol, Object>)

    This item schema’s item sets



44
45
46
# File 'lib/steam/community/game_item_schema.rb', line 44

def item_sets
  @item_sets
end

#itemsHash<Symbol, Object> (readonly)

The items defined for this game

Returns:

  • (Hash<Symbol, Object>)

    The items in this schema



49
50
51
# File 'lib/steam/community/game_item_schema.rb', line 49

def items
  @items
end

#languageSymbol (readonly)

The language of this item schema

Returns:

  • (Symbol)

    The language of this item schema



54
55
56
# File 'lib/steam/community/game_item_schema.rb', line 54

def language
  @language
end

#originsArray<String> (readonly)

The item origins defined for this game’s items

Returns:

  • (Array<String>)

    This item schema’s origins



59
60
61
# File 'lib/steam/community/game_item_schema.rb', line 59

def origins
  @origins
end

#qualitiesArray<String> (readonly)

The item qualities defined for this game’s items

Returns:

  • (Array<String>)

    This item schema’s qualities



64
65
66
# File 'lib/steam/community/game_item_schema.rb', line 64

def qualities
  @qualities
end

Instance Method Details

#fetchObject

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

#inspectString

Returns a short, human-readable string representation of this item schema

Returns:

  • (String)

    A 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