Class: WORLDCATAPI::GetRecordResponse

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(doc) ⇒ GetRecordResponse

Returns a new instance of GetRecordResponse.



9
10
11
12
13
# File 'lib/worldcatapi/get_record_response.rb', line 9

def initialize(doc)
  #super doc
  @raw = doc
  parse_marcxml(doc)
end

Instance Attribute Details

#rawObject

Returns the value of attribute raw.



7
8
9
# File 'lib/worldcatapi/get_record_response.rb', line 7

def raw
  @raw
end

#recordObject

Returns the value of attribute record.



7
8
9
# File 'lib/worldcatapi/get_record_response.rb', line 7

def record
  @record
end

Instance Method Details

#parse_marcxml(xml) ⇒ Object



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
# File 'lib/worldcatapi/get_record_response.rb', line 15

def parse_marcxml(xml)
   _title = ""
   #this is an array
   _author = Array.new()
   _link = ""
   _id = ""
   _citation = ""
   _summary = ""
   _xml = xml
   _rechash = {}
   _x = 0
   
   
   reader = MARC::XMLReader.new(StringIO.new(xml))
   
   for r in reader        
     @record = OpenStruct.new
     @record.id = r["001"].value
     @record.title = r['245']['a']
     @record.author = Array.new.push r['100']['a']
     @record.summary = r['500']['a']
     @record.link = "http://www.worldcat.org/oclc/#{@record.id}"
     @record.isbn = r['020']['a']
     @record.publisher = r['260'].value
     @record.edition = r['250']['a'] if r['250']
     @record.physical_description = r['300'].value
     
   end
   
   @record.xml = xml
      
   @record
end