Class: NintendoEshop::Game
- Inherits:
-
APIRequest
- Object
- APIRequest
- NintendoEshop::Game
- Defined in:
- lib/nintendo_eshop/game.rb
Instance Attribute Summary collapse
-
#art ⇒ Object
Returns the value of attribute art.
-
#categories ⇒ Object
Returns the value of attribute categories.
-
#description ⇒ Object
Returns the value of attribute description.
-
#esrb ⇒ Object
Returns the value of attribute esrb.
-
#id ⇒ Object
Returns the value of attribute id.
-
#msrp ⇒ Object
Returns the value of attribute msrp.
-
#object_id ⇒ Object
Returns the value of attribute object_id.
-
#platform ⇒ Object
Returns the value of attribute platform.
-
#release_date ⇒ Object
Returns the value of attribute release_date.
-
#sale_price ⇒ Object
Returns the value of attribute sale_price.
-
#title ⇒ Object
Returns the value of attribute title.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
- #current_price ⇒ Object
-
#initialize(id: nil, object_id: nil) ⇒ Game
constructor
A new instance of Game.
- #refresh ⇒ Object
- #release_date_pretty ⇒ Object
- #sale_percent ⇒ Object
Constructor Details
#initialize(id: nil, object_id: nil) ⇒ Game
Returns a new instance of Game.
16 17 18 19 |
# File 'lib/nintendo_eshop/game.rb', line 16 def initialize(id: nil, object_id: nil) self.id = id self.object_id = object_id end |
Instance Attribute Details
#art ⇒ Object
Returns the value of attribute art.
3 4 5 |
# File 'lib/nintendo_eshop/game.rb', line 3 def art @art end |
#categories ⇒ Object
Returns the value of attribute categories.
4 5 6 |
# File 'lib/nintendo_eshop/game.rb', line 4 def categories @categories end |
#description ⇒ Object
Returns the value of attribute description.
5 6 7 |
# File 'lib/nintendo_eshop/game.rb', line 5 def description @description end |
#esrb ⇒ Object
Returns the value of attribute esrb.
6 7 8 |
# File 'lib/nintendo_eshop/game.rb', line 6 def esrb @esrb end |
#id ⇒ Object
Returns the value of attribute id.
7 8 9 |
# File 'lib/nintendo_eshop/game.rb', line 7 def id @id end |
#msrp ⇒ Object
Returns the value of attribute msrp.
8 9 10 |
# File 'lib/nintendo_eshop/game.rb', line 8 def msrp @msrp end |
#object_id ⇒ Object
Returns the value of attribute object_id.
9 10 11 |
# File 'lib/nintendo_eshop/game.rb', line 9 def object_id @object_id end |
#platform ⇒ Object
Returns the value of attribute platform.
10 11 12 |
# File 'lib/nintendo_eshop/game.rb', line 10 def platform @platform end |
#release_date ⇒ Object
Returns the value of attribute release_date.
11 12 13 |
# File 'lib/nintendo_eshop/game.rb', line 11 def release_date @release_date end |
#sale_price ⇒ Object
Returns the value of attribute sale_price.
12 13 14 |
# File 'lib/nintendo_eshop/game.rb', line 12 def sale_price @sale_price end |
#title ⇒ Object
Returns the value of attribute title.
13 14 15 |
# File 'lib/nintendo_eshop/game.rb', line 13 def title @title end |
#url ⇒ Object
Returns the value of attribute url.
14 15 16 |
# File 'lib/nintendo_eshop/game.rb', line 14 def url @url end |
Class Method Details
.retrieve_by(id_type = {}) ⇒ Object
48 49 50 51 52 |
# File 'lib/nintendo_eshop/game.rb', line 48 def retrieve_by(id_type = {}) validate_argument(id_type) instance = new(id_type) instance.refresh end |
Instance Method Details
#current_price ⇒ Object
35 36 37 |
# File 'lib/nintendo_eshop/game.rb', line 35 def current_price sale_price || msrp end |
#refresh ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/nintendo_eshop/game.rb', line 21 def refresh response = request(:post, to_json: body) result = if response.dig(:hits)&.any? response.dig(:hits, 0) elsif response.dig(:results)&.any? response.dig(:results, 0) else raise InvalidRequestError, "ID not found" end refresh_object(result) self end |
#release_date_pretty ⇒ Object
39 40 41 |
# File 'lib/nintendo_eshop/game.rb', line 39 def release_date_pretty release_date.strftime("%b %d, %Y") end |
#sale_percent ⇒ Object
43 44 45 |
# File 'lib/nintendo_eshop/game.rb', line 43 def sale_percent ((1 - (sale_price / msrp)).round(2) * 100).to_i.to_s + "%" if sale_price end |