Class: WCAPI::GetRecordResponse
- Inherits:
-
Object
- Object
- WCAPI::GetRecordResponse
- Includes:
- XPath
- Defined in:
- lib/wcapi/get_record_response.rb
Instance Attribute Summary collapse
-
#raw ⇒ Object
Returns the value of attribute raw.
-
#record ⇒ Object
Returns the value of attribute record.
Instance Method Summary collapse
-
#initialize(doc) ⇒ GetRecordResponse
constructor
A new instance of GetRecordResponse.
- #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) ⇒ GetRecordResponse
Returns a new instance of GetRecordResponse.
6 7 8 9 10 |
# File 'lib/wcapi/get_record_response.rb', line 6 def initialize(doc) #super doc @raw = doc parse_marcxml(doc) end |
Instance Attribute Details
#raw ⇒ Object
Returns the value of attribute raw.
4 5 6 |
# File 'lib/wcapi/get_record_response.rb', line 4 def raw @raw end |
#record ⇒ Object
Returns the value of attribute record.
4 5 6 |
# File 'lib/wcapi/get_record_response.rb', line 4 def record @record 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 |
# File 'lib/wcapi/get_record_response.rb', line 12 def parse_marcxml(xml) _title = "" #this is an array = Array.new() _link = "" _id = "" _citation = "" _summary = "" _xml = xml _rechash = {} _x = 0 begin require 'rexml/document' doc = REXML::Document.new(xml) rescue #likely some kind of xml error end nodes = xpath_all(doc, "/record") puts "NODE Count: " + nodes.length.to_s nodes.each { |item | _title = xpath_get_text(xpath_first(item, "datafield[@tag='245']/subfield[@code='a']")) puts "TITLE: " + _title 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} } @record = _rechash end |