Class: WORLDCATAPI::SruSearchResponse
- Inherits:
-
Object
- Object
- WORLDCATAPI::SruSearchResponse
- Defined in:
- lib/worldcatapi/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
-
#extract_multiple(record, field, tag) ⇒ Object
Extract Multiple fields for record.
-
#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/worldcatapi/sru_search_response.rb', line 6 def initialize(doc) @raw = doc @header = OpenStruct.new parse_marcxml(doc) end |
Instance Attribute Details
#header ⇒ Object
Returns the value of attribute header.
4 5 6 |
# File 'lib/worldcatapi/sru_search_response.rb', line 4 def header @header end |
#raw ⇒ Object
Returns the value of attribute raw.
4 5 6 |
# File 'lib/worldcatapi/sru_search_response.rb', line 4 def raw @raw end |
#records ⇒ Object
Returns the value of attribute records.
4 5 6 |
# File 'lib/worldcatapi/sru_search_response.rb', line 4 def records @records end |
Instance Method Details
#extract_multiple(record, field, tag) ⇒ Object
Extract Multiple fields for record
60 61 62 63 64 65 66 |
# File 'lib/worldcatapi/sru_search_response.rb', line 60 def extract_multiple(record, field, tag) a = Array.new record.fields(field).each do |field| a.push field[tag] end return a end |
#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 |
# File 'lib/worldcatapi/sru_search_response.rb', line 12 def parse_marcxml(xml) @header = OpenStruct.new @records = Array.new 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 xml_records = doc.xpath("//records/record/recordData/record").to_xml reader = MARC::XMLReader.new(StringIO.new(xml_records)) reader.each do |r| record = OpenStruct.new record.id = r["001"].value record.title = r['245']['a'] record. = Array.new if r['100'] record..push r['100']['a'] if r['100'] elsif record. = extract_multiple(r, '700', 'a') end record.summary = extract_multiple(r,'500', 'a') if r['500'] record.isbn = extract_multiple(r, '020', 'a') record.publisher = r['260'].value if r['260'] record.published_date = r['260']['c'] if r['260'] record.edition = r['250']['a'] if r['250'] record.physical_description = r['300'].value if r['300'] record.link = "http://www.worldcat.org/oclc/#{record.id}" @records << record end @records end |