Class: WCAPI::SruSearchResponse
- Inherits:
-
Object
- Object
- WCAPI::SruSearchResponse
- Defined in:
- lib/wcapi/sru_search_response.rb
Instance Attribute Summary collapse
-
#header ⇒ Object
include WCAPI::XPath.
-
#raw ⇒ Object
include WCAPI::XPath.
-
#records ⇒ Object
include WCAPI::XPath.
Instance Method Summary collapse
-
#initialize(doc) ⇒ SruSearchResponse
constructor
A new instance of SruSearchResponse.
- #parse_marcxml(xml) ⇒ Object
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
include WCAPI::XPath
4 5 6 |
# File 'lib/wcapi/sru_search_response.rb', line 4 def header @header end |
#raw ⇒ Object
include WCAPI::XPath
4 5 6 |
# File 'lib/wcapi/sru_search_response.rb', line 4 def raw @raw end |
#records ⇒ Object
include WCAPI::XPath
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 |
# 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"?>', "") doc = Nokogiri::XML(xml) doc.remove_namespaces! @header["numberOfRecords"] = doc.xpath("//numberOfRecords").text @header["recordSchema"] = doc.xpath("//recordSchema").text @header["nextRecordPosition"] = doc.xpath("//nextRecordPosition").text @header["maxiumumRecords"] = doc.xpath("//maximumRecords").text @header["startRecord"] = doc.xpath("//startRecord").text nodes = doc.xpath("//records/record/recordData/record") nodes.each { |item | _title = item.xpath("datafield[@tag='245']/subfield[@code='a'][position()=1]").text if item.xpath("datafield[@tag='1*']") != nil item.xpath("datafield[@tag='1*']/sufield[@code='a']").each { |i| .push(i.text) } end if item.xpath("datafield[@tag='7*']") != nil item.xpath("datafield[@tag='7*']/sufield[@code='a']").each { |i| .push(i.text) } end if item.xpath("controlfield[@tag='001']") != nil _id = item.xpath("controlfield[@tag='001'][position()=1]").text _link = 'http://www.worldcat.org/oclc/' + _id.to_s end if item.xpath("datafield[@tag='520']") != nil _summary = item.xpath("datafield[@tag='520']/subfield[@code='a'][position()=1]").text else if item.xpath("datafield[@tag='500']") != nil _summary = item.xpath("datafield[@tag='500']/subfield[@code='a'][position()=1]").text end end _rechash = {:title => _title, :author => , :link => _link, :id => _id, :citation => _citation, :summary => _summary, :xml => item.to_s} _records.push(_rechash) } @records = _records end |