Sha256: a94e47a43b97fbf116b197acc0e09df7049ffd80f4fc479d9566ac999d4e97f3

Contents?: true

Size: 1.42 KB

Versions: 6

Compression:

Stored size: 1.42 KB

Contents

module Qa::Authorities
  class Oclcts::GenericOclcAuthority < Base
    attr_reader :subauthority

    def initialize(subauthority)
      super()
      @subauthority = subauthority
    end
    include WebServiceBase

    def search(q)
      get_raw_response("prefix-query", q)
      r = []
      raw_response.xpath('sru:searchRetrieveResponse/sru:records/sru:record/sru:recordData', 'sru' => 'http://www.loc.gov/zing/srw/').each do |record|
        r.append("id" => record.xpath('Zthes/term/termId').first.content, "label" => record.xpath('Zthes/term/termName').first.content)
      end
      r
    end

    def find(id)
      get_raw_response("id-lookup", id)
      parse_full_record(id)
    end

    private

      def parse_full_record(id)
        a = {}
        zthes_record = raw_response.xpath("sru:searchRetrieveResponse/sru:records/sru:record/sru:recordData/Zthes/term[termId='#{id}']", 'sru' => 'http://www.loc.gov/zing/srw/')
        zthes_record.children.each do |child|
          a[child.name] = child.children.first.to_s if (child.is_a? Nokogiri::XML::Element) && !child.children.nil? && (child.children.size == 1) && (child.children.first.is_a? Nokogiri::XML::Text)
        end
        a
      end

      def get_raw_response(query_type, id)
        query_url = Oclcts.url_pattern(query_type).gsub("{query}", id).gsub("{id}", id).gsub("{authority-id}", subauthority)
        @raw_response = Nokogiri::XML(URI.open(query_url))
      end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
qa-5.14.0 lib/qa/authorities/oclcts/generic_oclc_authority.rb
qa-5.13.0 lib/qa/authorities/oclcts/generic_oclc_authority.rb
qa-5.12.0 lib/qa/authorities/oclcts/generic_oclc_authority.rb
qa-5.11.0 lib/qa/authorities/oclcts/generic_oclc_authority.rb
qa-5.10.0 lib/qa/authorities/oclcts/generic_oclc_authority.rb
qa-5.9.0 lib/qa/authorities/oclcts/generic_oclc_authority.rb