class Qa::Authorities::Oclcts::GenericOclcAuthority
Attributes
Public Class Methods
new(subauthority)
click to toggle source
Calls superclass method
# File lib/qa/authorities/oclcts/generic_oclc_authority.rb, line 5 def initialize(subauthority) super() @subauthority = subauthority end
Public Instance Methods
find(id)
click to toggle source
# File lib/qa/authorities/oclcts/generic_oclc_authority.rb, line 20 def find(id) get_raw_response("id-lookup", id) parse_full_record(id) end
search(q)
click to toggle source
# File lib/qa/authorities/oclcts/generic_oclc_authority.rb, line 11 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
Private Instance Methods
get_raw_response(query_type, id)
click to toggle source
# File lib/qa/authorities/oclcts/generic_oclc_authority.rb, line 36 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
parse_full_record(id)
click to toggle source
# File lib/qa/authorities/oclcts/generic_oclc_authority.rb, line 27 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