Class: NintendoEshop::GamesList

Inherits:
APIRequest show all
Includes:
Enumerable
Defined in:
lib/nintendo_eshop/games_list.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title) ⇒ GamesList

Returns a new instance of GamesList.



8
9
10
# File 'lib/nintendo_eshop/games_list.rb', line 8

def initialize(title)
  self.title = title
end

Instance Attribute Details

#gamesObject

Returns the value of attribute games.



6
7
8
# File 'lib/nintendo_eshop/games_list.rb', line 6

def games
  @games
end

#titleObject

Returns the value of attribute title.



5
6
7
# File 'lib/nintendo_eshop/games_list.rb', line 5

def title
  @title
end

Class Method Details

.by_title(title) ⇒ Object



25
26
27
28
# File 'lib/nintendo_eshop/games_list.rb', line 25

def self.by_title(title)
  instance = new(title)
  instance.refresh
end

Instance Method Details

#eachObject



19
20
21
22
23
# File 'lib/nintendo_eshop/games_list.rb', line 19

def each
  games.each do |game|
    yield(game)
  end
end

#refreshObject



12
13
14
15
16
17
# File 'lib/nintendo_eshop/games_list.rb', line 12

def refresh
  response = request(:post, to_json: body)
  result = response.dig(:hits)
  self.games = refresh_list_objects(result)
  self
end