Class: WCAPI::GetRecordResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/wcapi/get_record_response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#rawObject

include WCAPI::XPath



4
5
6
# File 'lib/wcapi/get_record_response.rb', line 4

def raw
  @raw
end

#recordObject

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
   _author = 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|
      _author.push(i.xpath("subfield[@code='a']").text)
          }	
      end

      if item.xpath("datafield[@tag='7*']") != nil
   item.xpath("datafield[@tag='7*']").each {|i|
      _author.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 => _author, :link => _link, :id => _id, :citation => _citation, 
    :summary => _summary, :xml => item.to_s}
   }
   @record = _rechash
end