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

#extract_multiple(record, field, tag) ⇒ Object

Extract Multiple fields for record



48
49
50
51
52
53
54
# File 'lib/worldcatapi/get_record_response.rb', line 48

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



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

def parse_marcxml(xml)
   
   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        
     if r['100']
       @record.author.push r['100']['a'] if r['100']
     elsif
       @record.author = 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}"  
   end
   
   @record.xml = xml
      
   @record
end