Class: GamesRadar::Result
- Inherits:
-
Object
- Object
- GamesRadar::Result
- Defined in:
- lib/games_radar/result.rb
Instance Attribute Summary collapse
-
#count ⇒ Object
readonly
The total rows returned by the API.
-
#items ⇒ Object
readonly
The items array.
-
#page_size ⇒ Object
readonly
The number of items per page.
-
#pages ⇒ Object
readonly
The total pages.
Instance Method Summary collapse
-
#calculate_page_size ⇒ Object
:nodoc:.
-
#each(&block) ⇒ Object
A shortcut for
GamesRadar::Result#items.each
. -
#each_with_index(&block) ⇒ Object
A shortcut for
GamesRadar::Result#items.each_with_index
. -
#initialize(options = {}) ⇒ Result
constructor
Initialize a GamesRadar::Result by using a hash.
Constructor Details
#initialize(options = {}) ⇒ Result
Initialize a GamesRadar::Result by using a hash.
16 17 18 19 20 21 22 |
# File 'lib/games_radar/result.rb', line 16 def initialize( = {}) .each do |name, value| instance_variable_set("@#{name}", value) end calculate_page_size end |
Instance Attribute Details
#count ⇒ Object (readonly)
The total rows returned by the API
4 5 6 |
# File 'lib/games_radar/result.rb', line 4 def count @count end |
#items ⇒ Object (readonly)
The items array
10 11 12 |
# File 'lib/games_radar/result.rb', line 10 def items @items end |
#page_size ⇒ Object (readonly)
The number of items per page
13 14 15 |
# File 'lib/games_radar/result.rb', line 13 def page_size @page_size end |
#pages ⇒ Object (readonly)
The total pages
7 8 9 |
# File 'lib/games_radar/result.rb', line 7 def pages @pages end |
Instance Method Details
#calculate_page_size ⇒ Object
:nodoc:
38 39 40 41 42 43 44 |
# File 'lib/games_radar/result.rb', line 38 def calculate_page_size # :nodoc: if items.size == 0 @pages = 0 else @pages = (count.to_f / page_size).ceil end end |
#each(&block) ⇒ Object
A shortcut for GamesRadar::Result#items.each
25 26 27 28 29 |
# File 'lib/games_radar/result.rb', line 25 def each(&block) items.each do |item| yield item end end |
#each_with_index(&block) ⇒ Object
A shortcut for GamesRadar::Result#items.each_with_index
32 33 34 35 36 |
# File 'lib/games_radar/result.rb', line 32 def each_with_index(&block) items.each_with_index do |item, i| yield item, i end end |