Class: SteamCondenser::Community::GameItemSchema

Inherits:
Object
  • Object
show all
Includes:
Cacheable
Defined in:
lib/steam-condenser/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, #cache_id_value, #cache_ids, #cached_instance, #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


74
75
76
77
# File 'lib/steam-condenser/community/game_item_schema.rb', line 74

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


21
22
23
# File 'lib/steam-condenser/community/game_item_schema.rb', line 21

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


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

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


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

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


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

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


41
42
43
# File 'lib/steam-condenser/community/game_item_schema.rb', line 41

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


46
47
48
# File 'lib/steam-condenser/community/game_item_schema.rb', line 46

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


51
52
53
# File 'lib/steam-condenser/community/game_item_schema.rb', line 51

def items
  @items
end

#languageSymbol (readonly)

The language of this item schema

Returns:

  • (Symbol)

    The language of this item schema


56
57
58
# File 'lib/steam-condenser/community/game_item_schema.rb', line 56

def language
  @language
end

#originsArray<String> (readonly)

The item origins defined for this game's items

Returns:

  • (Array<String>)

    This item schema's origins


61
62
63
# File 'lib/steam-condenser/community/game_item_schema.rb', line 61

def origins
  @origins
end

#qualitiesArray<String> (readonly)

The item qualities defined for this game's items

Returns:

  • (Array<String>)

    This item schema's qualities


66
67
68
# File 'lib/steam-condenser/community/game_item_schema.rb', line 66

def qualities
  @qualities
end

Instance Method Details

#fetchObject

Updates the item definitions of this schema using the Steam Web API


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
123
124
# File 'lib/steam-condenser/community/game_item_schema.rb', line 80

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


129
130
131
# File 'lib/steam-condenser/community/game_item_schema.rb', line 129

def inspect
  "#<#{self.class}:#@app_id (#@language) - #{fetch_time || 'not fetched'}>"
end