Class: BackpackTF::ItemPrice
- Inherits:
-
Object
- Object
- BackpackTF::ItemPrice
- Includes:
- Finder
- Defined in:
- lib/backpack_tf/item_price.rb
Constant Summary collapse
- @@required_keys =
%w(currency value last_update difference)- @@qualities =
mapping official API quality integers to quality names https://wiki.teamfortress.com/wiki/WebAPI/GetSchema#Result_Data
[ :Normal, :Genuine, nil, :Vintage, nil, :Unusual, :Unique, :Community, :Valve, :"Self-Made", nil, :Strange, nil, :Haunted, :"Collector's" ]
- @@tradabilities =
[:Tradable, :'Non-Tradable']
- @@craftabilities =
[:Craftable, :'Non-Craftable']
Instance Attribute Summary collapse
-
#craftability ⇒ Symbol
readonly
Either :Craftable or :'Non-Craftable'.
-
#currency ⇒ Symbol
readonly
The currency that the item's price is based on.
-
#difference ⇒ Fixnum
readonly
A relative difference between the former price and the current price.
-
#last_update ⇒ Fixnum
readonly
A timestamp of when the price was last updated.
-
#priceindex ⇒ NilClass or Fixnum
readonly
Primarily used to signify crate series or unusual effect.
-
#quality ⇒ String
readonly
The quality of the item being priced, converted to String.
-
#tradability ⇒ Symbol
readonly
Either :Tradable or :'Non-Tradable'.
-
#value ⇒ Float
readonly
The value of the item in said currency.
-
#value_high ⇒ Float
readonly
The item's upper value measured in said currency.
-
#value_high_raw ⇒ Float
readonly
The item's value in the lowest currency without rounding.
-
#value_raw ⇒ Float
readonly
The item's value in the lowest currency without rounding.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(key, attr, priceindex = nil) ⇒ ItemPrice
constructor
A new instance of ItemPrice.
Methods included from Finder
Constructor Details
#initialize(key, attr, priceindex = nil) ⇒ ItemPrice
Returns a new instance of ItemPrice.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/backpack_tf/item_price.rb', line 30 def initialize key, attr, priceindex = nil attr = JSON.parse(attr) unless attr.class == Hash unless self.class.required_keys.all? {|k| attr.keys.member? k } raise KeyError, "The passed-in hash is required to have at least these 4 keys: #{self.class.required_keys.join(', ')}" end key_split = key.split('_') @priceindex = priceindex @quality = key_split[0].to_sym @tradability = key_split[1].to_sym @craftability = key_split[2].to_sym @currency = attr['currency'].to_sym @value = attr['value'] @value_high = attr['value_high'] @value_raw = attr['value_raw'] @value_high_raw = attr['value_high_raw'] @last_update = attr['last_update'] @difference = attr['difference'] end |
Instance Attribute Details
#craftability ⇒ Symbol (readonly)
Returns either :Craftable or :'Non-Craftable'.
12 13 14 |
# File 'lib/backpack_tf/item_price.rb', line 12 def craftability @craftability end |
#currency ⇒ Symbol (readonly)
Returns The currency that the item's price is based on.
16 17 18 |
# File 'lib/backpack_tf/item_price.rb', line 16 def currency @currency end |
#difference ⇒ Fixnum (readonly)
Returns A relative difference between the former price and the current price. If 0, assume new price.
28 29 30 |
# File 'lib/backpack_tf/item_price.rb', line 28 def difference @difference end |
#last_update ⇒ Fixnum (readonly)
Returns A timestamp of when the price was last updated.
26 27 28 |
# File 'lib/backpack_tf/item_price.rb', line 26 def last_update @last_update end |
#priceindex ⇒ NilClass or Fixnum (readonly)
Returns Primarily used to signify crate series or unusual effect. Otherwise, this is 0.
14 15 16 |
# File 'lib/backpack_tf/item_price.rb', line 14 def priceindex @priceindex end |
#quality ⇒ String (readonly)
Returns the quality of the item being priced, converted to String.
8 9 10 |
# File 'lib/backpack_tf/item_price.rb', line 8 def quality @quality end |
#tradability ⇒ Symbol (readonly)
Returns either :Tradable or :'Non-Tradable'.
10 11 12 |
# File 'lib/backpack_tf/item_price.rb', line 10 def tradability @tradability end |
#value ⇒ Float (readonly)
Returns The value of the item in said currency.
18 19 20 |
# File 'lib/backpack_tf/item_price.rb', line 18 def value @value end |
#value_high ⇒ Float (readonly)
Returns The item's upper value measured in said currency. only set if the item has a price range.
20 21 22 |
# File 'lib/backpack_tf/item_price.rb', line 20 def value_high @value_high end |
#value_high_raw ⇒ Float (readonly)
Returns The item's value in the lowest currency without rounding. Reques raw to be enabled and set to 2.
24 25 26 |
# File 'lib/backpack_tf/item_price.rb', line 24 def value_high_raw @value_high_raw end |
#value_raw ⇒ Float (readonly)
Returns The item's value in the lowest currency without rounding. If raw is set to 2, this is the lower value if a high value exists. Otherwise, this is the average between the high and low value. Requires raw to be enabled.
22 23 24 |
# File 'lib/backpack_tf/item_price.rb', line 22 def value_raw @value_raw end |
Class Method Details
.qualities ⇒ Object
75 |
# File 'lib/backpack_tf/item_price.rb', line 75 def self.qualities; @@qualities; end |
.required_keys ⇒ Object
53 |
# File 'lib/backpack_tf/item_price.rb', line 53 def self.required_keys; @@required_keys; end |