Class: WCAPI::SruSearchResponse
- Inherits:
-
Object
- Object
- WCAPI::SruSearchResponse
- Includes:
- XPath
- Defined in:
- lib/wcapi/sru_search_response.rb
Instance Attribute Summary collapse
-
#header ⇒ Object
Returns the value of attribute header.
-
#raw ⇒ Object
Returns the value of attribute raw.
-
#records ⇒ Object
Returns the value of attribute records.
Instance Method Summary collapse
-
#initialize(doc) ⇒ SruSearchResponse
constructor
A new instance of SruSearchResponse.
- #parse_marcxml(xml) ⇒ Object
Methods included from XPath
#get_attribute, #xpath, #xpath_all, #xpath_first, #xpath_get_all_text, #xpath_get_name, #xpath_get_text
Constructor Details
#initialize(doc) ⇒ SruSearchResponse
Returns a new instance of SruSearchResponse.
6 7 8 9 10 |
# File 'lib/wcapi/sru_search_response.rb', line 6 def initialize(doc) #super doc @raw = doc parse_marcxml(doc) end |
Instance Attribute Details
#header ⇒ Object
Returns the value of attribute header.
4 5 6 |
# File 'lib/wcapi/sru_search_response.rb', line 4 def header @header end |
#raw ⇒ Object
Returns the value of attribute raw.
4 5 6 |
# File 'lib/wcapi/sru_search_response.rb', line 4 def raw @raw end |
#records ⇒ Object
Returns the value of attribute records.
4 5 6 |
# File 'lib/wcapi/sru_search_response.rb', line 4 def records @records end |
Instance Method Details
#parse_marcxml(xml) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/wcapi/sru_search_response.rb', line 12 def parse_marcxml(xml) @header = {} _title = "" #this is an array = Array.new() _link = "" _id = "" _citation = "" _summary = "" _xml = xml _rechash = {} _records = Array.new() _x = 0 xml = xml.gsub('<?xml-stylesheet type="text/xsl" href="/webservices/catalog/xsl/searchRetrieveResponse.xsl"?>', "") begin require 'rexml/document' doc = REXML::Document.new(xml) rescue #likely some kind of xml error end @header["numberOfRecords"] = xpath_get_text(xpath_first(doc, "//numberOfRecords")) @header["recordSchema"] = xpath_get_text(xpath_first(doc, "//recordSchema")) @header["nextRecordPosition"] = xpath_get_text(xpath_first(doc, "//nextRecordPosition")) @header["maxiumumRecords"] = xpath_get_text(xpath_first(doc, "//maximumRecords")) @header["startRecord"] = xpath_get_text(xpath_first(doc, "//startRecord")) nodes = xpath_all(doc, "//records/record/recordData/record") nodes.each { |item | _title = xpath_get_text(xpath_first(item, "datafield[@tag='245']/subfield[@code='a']")) if xpath_first(item, "datafield[@tag='100']") != nil xpath_all(item, "datafield[@tag='100']/subfield[@code='a']").each { |i| .push(xpath_get_text(i)) } end if xpath_first(item, "datafield[@tag='700']" ) != nil xpath_all(item, "datafield[@tag='700']/subfield[@code='a']").each { |i| .push(xpath_get_text(i)) } end if xpath_first(item, "controlfield[@tag='001']") != nil _id = xpath_get_text(xpath_first(item, "controlfield[@tag='001']")) _link = 'http://www.worldcat.org/oclc/' + _id.to_s end if xpath_first(item, "datafield[@tag='520']") != nil _summary = xpath_get_text(xpath_first(item, "datafield[@tag='520']/subfield[@code='a']")) else if xpath_first(item, "datafield[@tag='500']") != nil _summary = xpath_get_text(xpath_first(item, "datafield[@tag='500']/subfield[@code='a']")) end end _rechash = {:title => _title, :author => , :link => _link, :id => _id, :citation => _citation, :summary => _summary, :xml => item.to_s} _records.push(_rechash) } @records = _records end |