Class: WCAPI::GetRecordResponse
- Inherits:
-
Object
- Object
- WCAPI::GetRecordResponse
- Defined in:
- lib/wcapi/get_record_response.rb
Instance Attribute Summary collapse
-
#raw ⇒ Object
include WCAPI::XPath.
-
#record ⇒ Object
include WCAPI::XPath.
Instance Method Summary collapse
-
#initialize(doc) ⇒ GetRecordResponse
constructor
A new instance of GetRecordResponse.
- #parse_marcxml(xml) ⇒ Object
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
include WCAPI::XPath
4 5 6 |
# File 'lib/wcapi/get_record_response.rb', line 4 def raw @raw end |
#record ⇒ Object
include WCAPI::XPath
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 |
# 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 doc = Nokogiri::XML(xml) doc.remove_namespaces! nodes = doc.xpath("/record") puts "NODE Count: " + nodes.length.to_s 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*']").each {|i| .push(i.xpath("subfield[@code='a']").text) } end if item.xpath("datafield[@tag='7*']") != nil item.xpath("datafield[@tag='7*']").each {|i| .push(i.xpath("subfield[@code='a']").text) } end if item.xpath("controlfield[@tag='001']") != nil _id = item.xpath("controlfield[@tag='001']").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} } @record = _rechash end |