Class: Google::CustomSearch::XML::Results

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/google/custom_search/xml/results.rb

Defined Under Namespace

Classes: Page

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Results

Returns a new instance of 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_pageObject



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

Returns:

  • (Boolean)


20
21
22
# File 'lib/google/custom_search/xml/results.rb', line 20

def empty?
  items.empty?
end

#lengthObject



24
25
26
# File 'lib/google/custom_search/xml/results.rb', line 24

def length
  items.length
end

#next_pageObject



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_pageObject



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