Class: CheapShark::Deal
- Inherits:
-
Object
- Object
- CheapShark::Deal
- Defined in:
- lib/cheapshark/models/deal.rb
Instance Attribute Summary collapse
-
#cheaper_stores ⇒ Object
readonly
Returns the value of attribute cheaper_stores.
-
#cheapest_date ⇒ Object
readonly
Returns the value of attribute cheapest_date.
-
#cheapest_price ⇒ Object
readonly
Returns the value of attribute cheapest_price.
-
#deal_rating ⇒ Object
readonly
Returns the value of attribute deal_rating.
-
#game_id ⇒ Object
readonly
Returns the value of attribute game_id.
-
#internal_name ⇒ Object
readonly
Returns the value of attribute internal_name.
-
#metacritic_link ⇒ Object
readonly
Returns the value of attribute metacritic_link.
-
#metacritic_score ⇒ Object
readonly
Returns the value of attribute metacritic_score.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#price ⇒ Object
readonly
Returns the value of attribute price.
-
#publisher ⇒ Object
readonly
Returns the value of attribute publisher.
-
#release_date ⇒ Object
readonly
Returns the value of attribute release_date.
-
#retail_price ⇒ Object
readonly
Returns the value of attribute retail_price.
-
#sale_price ⇒ Object
readonly
Returns the value of attribute sale_price.
-
#steam_app_id ⇒ Object
readonly
Returns the value of attribute steam_app_id.
-
#store_id ⇒ Object
readonly
Returns the value of attribute store_id.
-
#thumb ⇒ Object
readonly
Returns the value of attribute thumb.
Instance Method Summary collapse
-
#initialize(query_type, results) ⇒ Deal
constructor
TODO: DRY up this abomination.
Constructor Details
#initialize(query_type, results) ⇒ Deal
TODO: DRY up this abomination
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/cheapshark/models/deal.rb', line 8 def initialize(query_type, results) case query_type when :search @internal_name = results['internalName'] @name = results['title'] @deal_id = results['dealID'].to_i @store_id = results['storeID'].to_i @game_id = results['gameID'].to_i @sale_price = results['salePrice'].to_f @retail_price = results['normalPrice'].to_f @savings = results['savings'].to_f @metacritic_score = results['metacriticScore'].to_i @metacritic_link = results['metacriticLink'] @release_date = Time.at(results['releaseDate'].to_i) @last_change = Time.at(results['lastChange'].to_i) @deal_rating = results['dealRating'].to_f @thumb = results['thumb'] when :by_id @store_id = results['gameInfo']['storeID'].to_i @game_id = results['gameInfo']['gameID'].to_i @name = results['gameInfo']['name'] @steam_app_id = results['gameInfo']['steamAppID'].to_i @sale_price = results['gameInfo']['salePrice'].to_f @retail_price = results['gameInfo']['retailPrice'].to_f @metacritic_score = results['gameInfo']['metacriticScore'].to_i @metacritic_link = results['gameInfo']['metacriticLink'] @release_date = Time.at(results['gameInfo']['releaseDate'].to_i) @publisher = results['gameInfo']['publisher'] @thumb = results['gameInfo']['thumb'] @cheaper_stores = results['cheaperStores'].map { |deal| Deal.new :game, deal } @cheapest_price = results['cheapestPrice']['price'].to_f @cheapest_date = Time.at(results['cheapestPrice']['date'].to_i) when :game # derived from game object @store_id = results['storeID'] @deal_id = results['dealID'] @price = results['price'] @retail_price = results['retailPrice'] end end |
Instance Attribute Details
#cheaper_stores ⇒ Object (readonly)
Returns the value of attribute cheaper_stores.
5 6 7 |
# File 'lib/cheapshark/models/deal.rb', line 5 def cheaper_stores @cheaper_stores end |
#cheapest_date ⇒ Object (readonly)
Returns the value of attribute cheapest_date.
5 6 7 |
# File 'lib/cheapshark/models/deal.rb', line 5 def cheapest_date @cheapest_date end |
#cheapest_price ⇒ Object (readonly)
Returns the value of attribute cheapest_price.
5 6 7 |
# File 'lib/cheapshark/models/deal.rb', line 5 def cheapest_price @cheapest_price end |
#deal_rating ⇒ Object (readonly)
Returns the value of attribute deal_rating.
5 6 7 |
# File 'lib/cheapshark/models/deal.rb', line 5 def @deal_rating end |
#game_id ⇒ Object (readonly)
Returns the value of attribute game_id.
5 6 7 |
# File 'lib/cheapshark/models/deal.rb', line 5 def game_id @game_id end |
#internal_name ⇒ Object (readonly)
Returns the value of attribute internal_name.
5 6 7 |
# File 'lib/cheapshark/models/deal.rb', line 5 def internal_name @internal_name end |
#metacritic_link ⇒ Object (readonly)
Returns the value of attribute metacritic_link.
5 6 7 |
# File 'lib/cheapshark/models/deal.rb', line 5 def @metacritic_link end |
#metacritic_score ⇒ Object (readonly)
Returns the value of attribute metacritic_score.
5 6 7 |
# File 'lib/cheapshark/models/deal.rb', line 5 def @metacritic_score end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/cheapshark/models/deal.rb', line 5 def name @name end |
#price ⇒ Object (readonly)
Returns the value of attribute price.
5 6 7 |
# File 'lib/cheapshark/models/deal.rb', line 5 def price @price end |
#publisher ⇒ Object (readonly)
Returns the value of attribute publisher.
5 6 7 |
# File 'lib/cheapshark/models/deal.rb', line 5 def publisher @publisher end |
#release_date ⇒ Object (readonly)
Returns the value of attribute release_date.
5 6 7 |
# File 'lib/cheapshark/models/deal.rb', line 5 def release_date @release_date end |
#retail_price ⇒ Object (readonly)
Returns the value of attribute retail_price.
5 6 7 |
# File 'lib/cheapshark/models/deal.rb', line 5 def retail_price @retail_price end |
#sale_price ⇒ Object (readonly)
Returns the value of attribute sale_price.
5 6 7 |
# File 'lib/cheapshark/models/deal.rb', line 5 def sale_price @sale_price end |
#steam_app_id ⇒ Object (readonly)
Returns the value of attribute steam_app_id.
5 6 7 |
# File 'lib/cheapshark/models/deal.rb', line 5 def steam_app_id @steam_app_id end |
#store_id ⇒ Object (readonly)
Returns the value of attribute store_id.
5 6 7 |
# File 'lib/cheapshark/models/deal.rb', line 5 def store_id @store_id end |
#thumb ⇒ Object (readonly)
Returns the value of attribute thumb.
5 6 7 |
# File 'lib/cheapshark/models/deal.rb', line 5 def thumb @thumb end |