Class: CheapShark::Deal

Inherits:
Object
  • Object
show all
Defined in:
lib/cheapshark/models/deal.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_storesObject (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_dateObject (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_priceObject (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_ratingObject (readonly)

Returns the value of attribute deal_rating.



5
6
7
# File 'lib/cheapshark/models/deal.rb', line 5

def deal_rating
  @deal_rating
end

#game_idObject (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_nameObject (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

Returns the value of attribute metacritic_link.



5
6
7
# File 'lib/cheapshark/models/deal.rb', line 5

def metacritic_link
  @metacritic_link
end

#metacritic_scoreObject (readonly)

Returns the value of attribute metacritic_score.



5
6
7
# File 'lib/cheapshark/models/deal.rb', line 5

def metacritic_score
  @metacritic_score
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/cheapshark/models/deal.rb', line 5

def name
  @name
end

#priceObject (readonly)

Returns the value of attribute price.



5
6
7
# File 'lib/cheapshark/models/deal.rb', line 5

def price
  @price
end

#publisherObject (readonly)

Returns the value of attribute publisher.



5
6
7
# File 'lib/cheapshark/models/deal.rb', line 5

def publisher
  @publisher
end

#release_dateObject (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_priceObject (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_priceObject (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_idObject (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_idObject (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

#thumbObject (readonly)

Returns the value of attribute thumb.



5
6
7
# File 'lib/cheapshark/models/deal.rb', line 5

def thumb
  @thumb
end