Class: TCGPlayerSDK::ProductPriceList
- Inherits:
-
ResponseStruct
- Object
- OpenStruct
- ResponseStruct
- TCGPlayerSDK::ProductPriceList
- Defined in:
- lib/tcg-player-sdk/product_price_list.rb
Instance Method Summary collapse
-
#initialize(hash = {}) ⇒ ProductPriceList
constructor
A new instance of ProductPriceList.
-
#prices ⇒ Hash<Integer, Array<TCGPlayerSDK::ProductPrice>>
Returns a hash with productIds as keys, and a list of prices with subtypes as values: { 85736 => [ { “productId” => 85737, “lowPrice” => 4.99, “midPrice” => 5.63, “highPrice” => 7.73, “marketPrice” => 10.35, “directLowPrice” => nil, “subTypeName” => “Reverse Holofoil” }, { “productId” => 85737, “lowPrice” => nil, “midPrice” => nil, “highPrice” => nil, “marketPrice” => nil, “directLowPrice” => nil, “subTypeName” => “Unlimited Holofoil” }, ] }.
-
#valid_prices ⇒ Hash<Integer, Array<TCGPlayerSDK::ProductPrice>>
Weed out any ProductPrice objects that have no valid prices.
Methods inherited from ResponseStruct
#each, #keys, #method_missing, #respond_to_missing?, #to_h, #to_s, #try
Constructor Details
#initialize(hash = {}) ⇒ ProductPriceList
Returns a new instance of ProductPriceList.
3 4 5 |
# File 'lib/tcg-player-sdk/product_price_list.rb', line 3 def initialize(hash = {}) super end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class TCGPlayerSDK::ResponseStruct
Instance Method Details
#prices ⇒ Hash<Integer, Array<TCGPlayerSDK::ProductPrice>>
Returns a hash with productIds as keys, and a list of prices with subtypes as values:
{
85736 => [
{
"productId" => 85737,
"lowPrice" => 4.99,
"midPrice" => 5.63,
"highPrice" => 7.73,
"marketPrice" => 10.35,
"directLowPrice" => nil,
"subTypeName" => "Reverse Holofoil"
},
{
"productId" => 85737,
"lowPrice" => nil,
"midPrice" => nil,
"highPrice" => nil,
"marketPrice" => nil,
"directLowPrice" => nil,
"subTypeName" => "Unlimited Holofoil"
},
]
}
33 34 35 36 37 38 39 40 41 |
# File 'lib/tcg-player-sdk/product_price_list.rb', line 33 def prices if(self.success && self.results) @prices ||= self.results.map{|r| TCGPlayerSDK::ProductPrice.new(r)}.group_by{|r| r.productId} else @prices = {} end @prices end |
#valid_prices ⇒ Hash<Integer, Array<TCGPlayerSDK::ProductPrice>>
Weed out any ProductPrice objects that have no valid prices.
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/tcg-player-sdk/product_price_list.rb', line 47 def valid_prices if(@valid_prices.nil?) @valid_prices = {} @prices.each do |id, prl| @valid_prices[id] ||= [] @valid_prices[id] = prl.select{|pr| pr.has_valid_prices?} end end return @valid_prices end |