Class: TF2Item

Inherits:
Object
  • Object
show all
Defined in:
lib/steam/community/tf2/tf2_item.rb

Overview

Represents a Team Fortress 2 item

Constant Summary collapse

CLASSES =
[ :scout, :sniper, :soldier, :demoman, :medic, :heavy, :pyro, :spy ]
@@attribute_schema =
nil
@@item_schema =
nil
@@schema_language =
'en'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(item_data) ⇒ TF2Item

Creates a new instance of a TF2Item with the given data



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/steam/community/tf2/tf2_item.rb', line 46

def initialize(item_data)
  update_schema if @@item_schema.nil?

  @defindex          = item_data[:defindex]

  @backpack_position = item_data[:inventory] & 0xffff
  @class             = @@item_schema[@defindex][:item_class]
  @count             = item_data[:quantity]
  @id                = item_data[:id]
  @level             = item_data[:level]
  @name              = @@item_schema[@defindex][:item_name]
  @quality           = @@qualities[item_data[:quality]]
  @slot              = @@item_schema[@defindex][:item_slot]
  @type              = @@item_schema[@defindex][:item_type_name]

  @equipped = {}
  CLASSES.each_index do |class_id|
    @equipped[CLASSES[class_id]] = (item_data[:inventory] & (1 << 16 + class_id) != 0)
  end

  unless @@item_schema[@defindex][:attributes].nil?
    @attributes = @@item_schema[@defindex][:attributes][:attribute]
  end
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



13
14
15
# File 'lib/steam/community/tf2/tf2_item.rb', line 13

def attributes
  @attributes
end

#backpack_positionObject (readonly)

Returns the value of attribute backpack_position.



13
14
15
# File 'lib/steam/community/tf2/tf2_item.rb', line 13

def backpack_position
  @backpack_position
end

#classObject (readonly)

Returns the value of attribute class.



13
14
15
# File 'lib/steam/community/tf2/tf2_item.rb', line 13

def class
  @class
end

#countObject (readonly)

Returns the value of attribute count.



13
14
15
# File 'lib/steam/community/tf2/tf2_item.rb', line 13

def count
  @count
end

#defindexObject (readonly)

Returns the value of attribute defindex.



13
14
15
# File 'lib/steam/community/tf2/tf2_item.rb', line 13

def defindex
  @defindex
end

#idObject (readonly)

Returns the value of attribute id.



13
14
15
# File 'lib/steam/community/tf2/tf2_item.rb', line 13

def id
  @id
end

#levelObject (readonly)

Returns the value of attribute level.



13
14
15
# File 'lib/steam/community/tf2/tf2_item.rb', line 13

def level
  @level
end

#nameObject (readonly)

Returns the value of attribute name.



13
14
15
# File 'lib/steam/community/tf2/tf2_item.rb', line 13

def name
  @name
end

#qualityObject (readonly)

Returns the value of attribute quality.



13
14
15
# File 'lib/steam/community/tf2/tf2_item.rb', line 13

def quality
  @quality
end

#slotObject (readonly)

Returns the value of attribute slot.



13
14
15
# File 'lib/steam/community/tf2/tf2_item.rb', line 13

def slot
  @slot
end

#typeObject (readonly)

Returns the value of attribute type.



13
14
15
# File 'lib/steam/community/tf2/tf2_item.rb', line 13

def type
  @type
end

Class Method Details

.attribute_schemaObject

Returns the attribute schema

The attribute schema is fetched first if not done already



25
26
27
28
29
# File 'lib/steam/community/tf2/tf2_item.rb', line 25

def self.attribute_schema
  update_schema if @@attribute_schema.nil?

  @@attribute_schema
end

.item_schemaObject

Returns the item schema

The item schema is fetched first if not done already



34
35
36
37
38
# File 'lib/steam/community/tf2/tf2_item.rb', line 34

def self.item_schema
  update_schema if @@item_schema.nil?

  @@item_schema
end

.schema_language=(language) ⇒ Object

Sets the language the schema should be fetched in (default is: ‘en’)



41
42
43
# File 'lib/steam/community/tf2/tf2_item.rb', line 41

def self.schema_language=(language)
  @@schema_language = language
end

Instance Method Details

#classes_equipped?Boolean

Returns the class symbols for each class this player has equipped this item

Returns:

  • (Boolean)


72
73
74
# File 'lib/steam/community/tf2/tf2_item.rb', line 72

def classes_equipped?
  @equipped.reject { |class_id, equipped| !equipped }
end

#equipped?Boolean

Returns whether this item is equipped by this player at all

Returns:

  • (Boolean)


77
78
79
# File 'lib/steam/community/tf2/tf2_item.rb', line 77

def equipped?
  @equipped.has_value? true
end