Class: SRU::SearchResponse

Inherits:
Response show all
Includes:
Enumerable
Defined in:
lib/sru/search_retrieve.rb

Overview

An iterator for search results which allows you to do stuff like:

client = SRU::Client.new 'http://sru.example.com'
for record in client.search_retrieve('Mark Twain')
  puts record 
end

The records returned are REXML::Document objects.

Instance Attribute Summary

Attributes inherited from Response

#doc, #namespaces, #parser

Instance Method Summary collapse

Methods inherited from Response

#initialize

Methods included from XPath

#get_attribute, #xpath, #xpath_all, #xpath_first

Constructor Details

This class inherits a constructor from SRU::Response

Instance Method Details

#eachObject

Returns the contents of each recordData element in a SRU searchRetrieve response.



24
25
26
27
28
29
30
31
# File 'lib/sru/search_retrieve.rb', line 24

def each
  obj = xpath_all(@doc, './/zs:recordData', @namespaces)
  for record_data in obj
    if obj.size > 0
      yield record_data
    end
  end
end

#number_of_recordsObject



17
18
19
# File 'lib/sru/search_retrieve.rb', line 17

def number_of_records
  return Integer(xpath(@doc, './/zs:numberOfRecords', @namespaces))
end