Sha256: 6a8bde2f0b958e0c6debbe9639016af25f67241a77067163b4d545f84b765a52
Contents?: true
Size: 1.6 KB
Versions: 1
Compression:
Stored size: 1.6 KB
Contents
module Voyager module Holdings class Collection attr_reader :records, :xml DEFAULT_OPAC_URL = "http://bearberry.cc.columbia.edu:7014/vxws/GetHoldingsService" # Invoke GetHoldingsService def self.new_from_opac(bibid, url = DEFAULT_OPAC_URL, httpclient = nil) conn = Voyager::Connection.new(:http_client => httpclient) Collection.new(conn.request(url, :bibId => bibid)) end # Convert raw xml from GetHoldingsService to xml record object def initialize(raw_xml) @xml = load_and_namespace_xml(raw_xml) parse_xml end # Generate output hash from Record class instances def to_hash output = {} output[:records] = @records.collect do |rec| rec.to_hash end output end private # Create xml record object with searchable namespaces def load_and_namespace_xml(raw_xml) xml = Nokogiri::XML(raw_xml) xml.root.add_namespace_definition("hol", "http://www.endinfosys.com/Voyager/holdings") xml.root.add_namespace_definition("mfhd", "http://www.endinfosys.com/Voyager/mfhd") xml.root.add_namespace_definition("item", "http://www.endinfosys.com/Voyager/item") xml.root.add_namespace_definition("slim", "http://www.loc.gov/MARC21/slim") return xml end # Collect Record class instances for each mfhd:mfhdRecord node in xml record objext def parse_xml @records = @xml.css("hol|mfhdCollection>mfhd|mfhdRecord").collect do |record_node| Record.new(record_node) end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
voyager_api-0.1.1 | lib/holdings/collection.rb |