Skip to content

Commit

Permalink
Added Response#estimated_count
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Jul 23, 2009
1 parent 4d2bfc3 commit 2a89c8c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
1 change: 0 additions & 1 deletion README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

== Todo

* local?
* response.estimated_count
* response.get_more # => Response
* start ? make sure paging works
Expand Down
6 changes: 6 additions & 0 deletions lib/google-search/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,19 @@ class Response

attr_reader :items

##
# Estimated number of results.

attr_reader :estimated_count

##
# Initialize with _hash_.

def initialize hash
@hash = hash
@status = hash['responseStatus']
@details = hash['responseDetails']
@estimated_count = hash['responseData']['cursor']['estimatedResultCount'].to_i rescue 0
@items = []
if valid?
@items = @hash['responseData']['results'].map do |result|
Expand Down
13 changes: 11 additions & 2 deletions spec/response_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
require File.dirname(__FILE__) + '/spec_helper'

describe Google::Search::Response do
before :each do
@response = Google::Search::Response.new json_fixture('web-response')
end

describe "#valid?" do
it "should return false when response status is not 200" do
response = Google::Search::Response.new 'responseStatus' => 400
Expand All @@ -16,8 +20,13 @@

describe "#items" do
it "should be an array of items" do
response = Google::Search::Response.new json_fixture('web-response')
response.items.first.should be_a(Google::Search::Item)
@response.items.first.should be_a(Google::Search::Item)
end
end

describe "#estimated_count" do
it "should be set" do
@response.estimated_count.should == 33400000
end
end
end

0 comments on commit 2a89c8c

Please sign in to comment.