mlangenberg-googlesearch 0.2.2 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/googlesearch.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'googlesearch'
3
- s.version = '0.2.2'
4
- s.date = '2009-01-20'
3
+ s.version = '0.2.3'
4
+ s.date = '2009-01-21'
5
5
  s.platform = Gem::Platform::RUBY
6
6
  s.has_rdoc = false
7
7
  s.summary = 'Google CSE implementation'
@@ -1,8 +1,8 @@
1
1
  class SearchPage
2
2
  #index is zero-based
3
- def initialize(index, response_start_index, results_per_page)
3
+ def initialize(index, index_of_last_result, results_per_page)
4
4
  @index = index
5
- @response_start_index = response_start_index
5
+ @index_of_last_result = index_of_last_result
6
6
  @results_per_page = results_per_page
7
7
  end
8
8
 
@@ -15,6 +15,6 @@ class SearchPage
15
15
  end
16
16
 
17
17
  def current_page?
18
- start_index == @response_start_index.to_i
18
+ (@index_of_last_result/@results_per_page) == page_number
19
19
  end
20
20
  end
@@ -18,7 +18,7 @@ class SearchResponse
18
18
  end
19
19
 
20
20
  def pages
21
- @pages ||= number_of_pages.enum_for(:times).collect { |page_index| SearchPage.new(page_index, start_index, requested_number_of_search_results) }
21
+ @pages ||= number_of_pages.enum_for(:times).collect { |page_index| SearchPage.new(page_index, index_of_last_result, requested_number_of_search_results) }
22
22
  end
23
23
 
24
24
  def current_page
@@ -30,6 +30,7 @@ class SearchResponse
30
30
  end
31
31
 
32
32
  def next_page
33
+ return nil if pages.empty?
33
34
  pages[pages.index(current_page)+1]
34
35
  end
35
36
  end
@@ -7,7 +7,7 @@ describe GoogleSearch do
7
7
  'http://www.google.com/search?&q=adres&client=google-csbe&output=xml_no_dtd&cx=unique-cse-id&cr=lang_nl&lr=lang_nl&start=0&num=10'
8
8
  ).and_return('wat_xml')
9
9
 
10
- SearchResponse.should_receive(:new).with('wat_xml', 10).and_return('search-response-object')
10
+ SearchResponse.should_receive(:new).with('wat_xml', 10, 0).and_return('search-response-object')
11
11
  search = GoogleSearch.new({:cx => 'unique-cse-id', :q => 'adres', :cr => 'nl', :lr => 'nl', :start => 0, :num => 10 }, request_mock)
12
12
  search.response.should == 'search-response-object'
13
13
  end
@@ -2,27 +2,28 @@ require File.join(File.dirname(__FILE__), 'spec_helper')
2
2
 
3
3
  describe SearchPage do
4
4
  it "should have page number of 1" do
5
- p = SearchPage.new(0, 0, 10)
5
+ p = SearchPage.new(0, 10, 10)
6
6
  p.page_number.should == 1
7
7
  end
8
8
 
9
9
  it "should have a start index of 0 when the index is 0" do
10
- p = SearchPage.new(0, 0, 10)
10
+ p = SearchPage.new(0, 10, 10)
11
11
  p.start_index.should == 0
12
12
  end
13
13
 
14
14
  it "should have a start index of 10 when the index is 1 and the requested number of results is 10" do
15
- p = SearchPage.new(1, 0, 10)
15
+ p = SearchPage.new(1, 10, 10)
16
16
  p.start_index.should == 10
17
17
  end
18
18
 
19
- it "should know that it is the current page if the given page index equals the start index" do
20
- p = SearchPage.new(1, 10, 10)
19
+ it "should be the current page" do
20
+ p = SearchPage.new(1, 20, 10)
21
+ p.page_number.should == 2
21
22
  p.should be_current_page
22
23
  end
23
24
 
24
- it "should know that it is not the current page if the given page index does not equal the start index" do
25
- p = SearchPage.new(0, 10, 10)
25
+ it "should not be the current page" do
26
+ p = SearchPage.new(0, 20, 10)
26
27
  p.should_not be_current_page
27
28
  end
28
29
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mlangenberg-googlesearch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rene Heino
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-01-20 00:00:00 -08:00
13
+ date: 2009-01-21 00:00:00 -08:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency