Class: BackpackTF::ItemPrice

Inherits:
Object
  • Object
show all
Defined in:
lib/backpack_tf/item_price.rb

Constant Summary collapse

@@required_keys =

Class Methods

['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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, attr, priceindex = nil) ⇒ ItemPrice

Returns a new instance of ItemPrice.



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/backpack_tf/item_price.rb', line 64

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'.

Returns:

  • (Symbol) —

    either :Craftable or :'Non-Craftable'



46
47
48
# File 'lib/backpack_tf/item_price.rb', line 46

def craftability
  @craftability
end

#currency ⇒ Symbol (readonly)

Returns The currency that the item's price is based on.

Returns:

  • (Symbol) —

    The currency that the item's price is based on



50
51
52
# File 'lib/backpack_tf/item_price.rb', line 50

def currency
  @currency
end

#difference ⇒ Fixnum (readonly)

Returns A relative difference between the former price and the current price. If 0, assume new price.

Returns:

  • (Fixnum) —

    A relative difference between the former price and the current price. If 0, assume new price.



62
63
64
# File 'lib/backpack_tf/item_price.rb', line 62

def difference
  @difference
end

#last_update ⇒ Fixnum (readonly)

Returns A timestamp of when the price was last updated.

Returns:

  • (Fixnum) —

    A timestamp of when the price was last updated



60
61
62
# File 'lib/backpack_tf/item_price.rb', line 60

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.

Returns:

  • (NilClass or Fixnum) —

    Primarily used to signify crate series or unusual effect. Otherwise, this is 0



48
49
50
# File 'lib/backpack_tf/item_price.rb', line 48

def priceindex
  @priceindex
end

#quality ⇒ String (readonly)

Returns the quality of the item being priced, converted to String.

Returns:

  • (String) —

    the quality of the item being priced, converted to String



42
43
44
# File 'lib/backpack_tf/item_price.rb', line 42

def quality
  @quality
end

#tradability ⇒ Symbol (readonly)

Returns either :Tradable or :'Non-Tradable'.

Returns:

  • (Symbol) —

    either :Tradable or :'Non-Tradable'



44
45
46
# File 'lib/backpack_tf/item_price.rb', line 44

def tradability
  @tradability
end

#value ⇒ Float (readonly)

Returns The value of the item in said currency.

Returns:

  • (Float) —

    The value of the item in said currency



52
53
54
# File 'lib/backpack_tf/item_price.rb', line 52

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.

Returns:

  • (Float) —

    The item's upper value measured in said currency. only set if the item has a price range



54
55
56
# File 'lib/backpack_tf/item_price.rb', line 54

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.

Returns:

  • (Float) —

    The item's value in the lowest currency without rounding. Reques raw to be enabled and set to 2



58
59
60
# File 'lib/backpack_tf/item_price.rb', line 58

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.

Returns:

  • (Float) —

    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.



56
57
58
# File 'lib/backpack_tf/item_price.rb', line 56

def value_raw
  @value_raw
end

Class Method Details

.qualities ⇒ Object



32
# File 'lib/backpack_tf/item_price.rb', line 32

def self.qualities; @@qualities; end

.required_keys ⇒ Object



10
# File 'lib/backpack_tf/item_price.rb', line 10

def self.required_keys; @@required_keys; end