Class: GoogleBooks::API::Response

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/google_books/api/response.rb

Instance Method Summary collapse

Constructor Details

#initialize(results) ⇒ Response

Returns a new instance of Response.



6
7
8
# File 'lib/google_books/api/response.rb', line 6

def initialize(results)
  @results = results
end

Instance Method Details

#each(&block) ⇒ Object

Iterator for looping through the results



11
12
13
14
15
# File 'lib/google_books/api/response.rb', line 11

def each(&block)
  @results['items'].each do |item|
    block.call(Book.new(item))
  end
end

#total_resultsObject

The total number of results that were found for your query (not the count of the results returned)



18
19
20
# File 'lib/google_books/api/response.rb', line 18

def total_results
  @results['totalItems'].to_i
end