Class: BackpackTF::ItemPrice
- Inherits:
-
Object
- Object
- BackpackTF::ItemPrice
- Defined in:
- lib/backpack_tf/item_price.rb
Constant Summary collapse
- KEYNAME_DELIMITER =
'_'
- PARTICLE_EFFECTS_KEY =
'attribute_controlled_attached_particles'
- PARTICLE_EFFECTS_FILE =
"./lib/backpack_tf/assets/#{PARTICLE_EFFECTS_KEY}.json"
- @@qualities =
mapping official API quality integers to quality names 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']
- @@required_keys =
['currency', 'value', 'last_update', 'difference']
- @@particle_effects =
self.hash_particle_effects
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.
-
#effect ⇒ String
readonly
Result of @@particle_effects.
-
#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
- .hash_particle_effects ⇒ Object
- .ins_sp(str) ⇒ Object
- .particle_effects ⇒ Object
- .qualities ⇒ Object
- .quality_name_to_index(q) ⇒ Object
- .required_keys ⇒ Object
Instance Method Summary collapse
-
#initialize(key, attr, priceindex = nil) ⇒ ItemPrice
constructor
A new instance of ItemPrice.
Constructor Details
#initialize(key, attr, priceindex = nil) ⇒ ItemPrice
Returns a new instance of ItemPrice.
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/backpack_tf/item_price.rb', line 107 def initialize key, attr, priceindex = nil attr = JSON.parse(attr) unless attr.class == Hash key = key.split(KEYNAME_DELIMITER) key = process_key(key) validate_attributes(attr) @quality = key[0] @tradability = key[1] @craftability = key[2] @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'] @priceindex = priceindex @effect = self.class.particle_effects[priceindex.to_i] end |
Instance Attribute Details
#craftability ⇒ Symbol (readonly)
Returns either :Craftable or :‘Non-Craftable’.
87 88 89 |
# File 'lib/backpack_tf/item_price.rb', line 87 def craftability @craftability end |
#currency ⇒ Symbol (readonly)
Returns The currency that the item’s price is based on.
91 92 93 |
# File 'lib/backpack_tf/item_price.rb', line 91 def currency @currency end |
#difference ⇒ Fixnum (readonly)
Returns A relative difference between the former price and the current price. If 0, assume new price.
103 104 105 |
# File 'lib/backpack_tf/item_price.rb', line 103 def difference @difference end |
#effect ⇒ String (readonly)
Returns Result of @@particle_effects.
105 106 107 |
# File 'lib/backpack_tf/item_price.rb', line 105 def effect @effect end |
#last_update ⇒ Fixnum (readonly)
Returns A timestamp of when the price was last updated.
101 102 103 |
# File 'lib/backpack_tf/item_price.rb', line 101 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.
89 90 91 |
# File 'lib/backpack_tf/item_price.rb', line 89 def priceindex @priceindex end |
#quality ⇒ String (readonly)
Returns the quality of the item being priced, converted to String.
83 84 85 |
# File 'lib/backpack_tf/item_price.rb', line 83 def quality @quality end |
#tradability ⇒ Symbol (readonly)
Returns either :Tradable or :‘Non-Tradable’.
85 86 87 |
# File 'lib/backpack_tf/item_price.rb', line 85 def tradability @tradability end |
#value ⇒ Float (readonly)
Returns The value of the item in said currency.
93 94 95 |
# File 'lib/backpack_tf/item_price.rb', line 93 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.
95 96 97 |
# File 'lib/backpack_tf/item_price.rb', line 95 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.
99 100 101 |
# File 'lib/backpack_tf/item_price.rb', line 99 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.
97 98 99 |
# File 'lib/backpack_tf/item_price.rb', line 97 def value_raw @value_raw end |
Class Method Details
.hash_particle_effects ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/backpack_tf/item_price.rb', line 44 def self.hash_particle_effects file = File.open(PARTICLE_EFFECTS_FILE).read effects_arr = JSON.parse(file)[PARTICLE_EFFECTS_KEY] effects_arr.inject({}) do |hash, pe| id = pe['id'] name = pe['name'] hash[id] = name hash end end |
.ins_sp(str) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/backpack_tf/item_price.rb', line 61 def self.ins_sp str str = str.split('') new_str = '' str.each_with_index do |c, i| if i == 0 new_str += c else unless c == c.upcase && str[i-1] == str[i-1].upcase new_str += c else new_str += (' ' + c) end end end new_str end |
.particle_effects ⇒ Object
59 |
# File 'lib/backpack_tf/item_price.rb', line 59 def self.particle_effects; @@particle_effects; end |
.qualities ⇒ Object
37 |
# File 'lib/backpack_tf/item_price.rb', line 37 def self.qualities; @@qualities; end |
.quality_name_to_index(q) ⇒ Object
40 41 42 |
# File 'lib/backpack_tf/item_price.rb', line 40 def self.quality_name_to_index q @@qualities.index(q.to_sym) unless q.nil? end |
.required_keys ⇒ Object
38 |
# File 'lib/backpack_tf/item_price.rb', line 38 def self.required_keys; @@required_keys; end |