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,8 +1,8 @@
|
|
1
1
|
class SearchPage
|
2
2
|
#index is zero-based
|
3
|
-
def initialize(index,
|
3
|
+
def initialize(index, index_of_last_result, results_per_page)
|
4
4
|
@index = index
|
5
|
-
@
|
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
|
-
|
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,
|
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
|
data/spec/google_search_spec.rb
CHANGED
@@ -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
|
data/spec/search_page_spec.rb
CHANGED
@@ -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,
|
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,
|
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,
|
15
|
+
p = SearchPage.new(1, 10, 10)
|
16
16
|
p.start_index.should == 10
|
17
17
|
end
|
18
18
|
|
19
|
-
it "should
|
20
|
-
p = SearchPage.new(1,
|
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
|
25
|
-
p = SearchPage.new(0,
|
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.
|
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-
|
13
|
+
date: 2009-01-21 00:00:00 -08:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|