Class: Google::CustomSearch::XML::Results
- Inherits:
-
Object
- Object
- Google::CustomSearch::XML::Results
- Includes:
- Enumerable
- Defined in:
- lib/google/custom_search/xml/results.rb
Defined Under Namespace
Classes: Page
Instance Method Summary collapse
- #current_page ⇒ Object
- #each(&block) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(response) ⇒ Results
constructor
A new instance of Results.
- #length ⇒ Object
- #next_page ⇒ Object
- #previous_page ⇒ Object
Constructor Details
#initialize(response) ⇒ Results
12 13 14 |
# File 'lib/google/custom_search/xml/results.rb', line 12 def initialize(response) @doc = Nokogiri::XML.parse(response) end |
Instance Method Details
#current_page ⇒ Object
33 34 35 |
# File 'lib/google/custom_search/xml/results.rb', line 33 def current_page Page.from_xml(@doc.search('//RES').first) end |
#each(&block) ⇒ Object
16 17 18 |
# File 'lib/google/custom_search/xml/results.rb', line 16 def each(&block) items.each(&block) end |
#empty? ⇒ Boolean
20 21 22 |
# File 'lib/google/custom_search/xml/results.rb', line 20 def empty? items.empty? end |
#length ⇒ Object
24 25 26 |
# File 'lib/google/custom_search/xml/results.rb', line 24 def length items.length end |
#next_page ⇒ Object
28 29 30 31 |
# File 'lib/google/custom_search/xml/results.rb', line 28 def next_page return current_page unless @doc.search('//RES/NB').any? Page.new(current_page.end_index + 1, current_page.end_index + 11, 10) end |
#previous_page ⇒ Object
37 38 39 40 |
# File 'lib/google/custom_search/xml/results.rb', line 37 def previous_page return current_page if current_page.start_index == 1 Page.new(current_page.start_index - 10, current_page.start_index, 10) end |