Class: GamesRadar::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/games_radar/result.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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(options = {})
  options.each do |name, value|
    instance_variable_set("@#{name}", value)
  end

  calculate_page_size
end

Instance Attribute Details

#countObject (readonly)

The total rows returned by the API



4
5
6
# File 'lib/games_radar/result.rb', line 4

def count
  @count
end

#itemsObject (readonly)

The items array



10
11
12
# File 'lib/games_radar/result.rb', line 10

def items
  @items
end

#page_sizeObject (readonly)

The number of items per page



13
14
15
# File 'lib/games_radar/result.rb', line 13

def page_size
  @page_size
end

#pagesObject (readonly)

The total pages



7
8
9
# File 'lib/games_radar/result.rb', line 7

def pages
  @pages
end

Instance Method Details

#calculate_page_sizeObject

: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