Class: WCAPI::GetLocationResponse

Inherits:
Object
  • Object
show all
Includes:
XPath
Defined in:
lib/wcapi/get_location_response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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) ⇒ GetLocationResponse

Returns a new instance of GetLocationResponse.



6
7
8
9
10
# File 'lib/wcapi/get_location_response.rb', line 6

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

Instance Attribute Details

#institutionsObject

Returns the value of attribute institutions.



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

def institutions
  @institutions
end

#rawObject

Returns the value of attribute raw.



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

def raw
  @raw
end

Instance Method Details

#parse_holdings(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
# File 'lib/wcapi/get_location_response.rb', line 12

def parse_holdings(xml)
   _oclc_symbol = ""
   _link = ""
   _copies = ""
   _xml = xml
   _instchash = {}
   _records = Array.new()
   _x = 0

   begin
     require 'xml/libxml'
     _parser = LibXML::XML::Parser.new()
     _parser.string = xml
     doc = LibXML::XML::Document.new()
     doc = _parser.parse
   rescue
     begin
        require 'rexml/document'
        doc = REXML::Document.new(xml)
     rescue
        #likely some kind of xml error
     end
   end

   nodes = xpath_all(doc, "//holding")
   nodes.each { |item |
      _oclc_symbol = xpath_get_text(xpath_first(item, "institutionIdentifier/value")) 

      if xpath_first(item, "electronicAddress/text") != nil 
        _link = xpath_get_text(xpath_first(item, "electronicAddress/text")) 
      end

      if xpath_first(item, "holdingSimple/copiesSummary/copiesCount") != nil
  _copies = xpath_get_text(xpath_first(item, "holdingSimple/copiesSummary/copiesCount"))
	 end

      _instchash = {:institutionIdentifier => _oclc_symbol, :link => _link, :copies => _copies ,
    :xml => item.to_s}
	_records.push(_instchash)
   }
   @institutions = _records
end