Class: Qa::Authorities::Oclcts

Inherits:
Base
  • Object
show all
Extended by:
Deprecation
Defined in:
lib/qa/authorities/oclcts.rb

Constant Summary collapse

SRU_SERVER_CONFIG =
YAML.load_file(Rails.root.join("config", "oclcts-authorities.yml"))

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeOclcts

Returns a new instance of Oclcts.



12
13
# File 'lib/qa/authorities/oclcts.rb', line 12

def initialize
end

Instance Attribute Details

#sub_authorityObject

Returns the value of attribute sub_authority.



10
11
12
# File 'lib/qa/authorities/oclcts.rb', line 10

def sub_authority
  @sub_authority
end

Class Method Details

.authority_valid?(sub_authority) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/qa/authorities/oclcts.rb', line 15

def self.authority_valid?(sub_authority)
  self.sub_authorities.include?(sub_authority)
end

.sub_authoritiesObject



19
20
21
# File 'lib/qa/authorities/oclcts.rb', line 19

def self.sub_authorities
  @sub_authorities ||= SRU_SERVER_CONFIG["authorities"].map { |sub_authority| sub_authority[0] }
end

Instance Method Details

#full_record(id, sub_authority) ⇒ Object



32
33
34
35
# File 'lib/qa/authorities/oclcts.rb', line 32

def full_record(id, sub_authority)
  raw_response = get_raw_response("id-lookup", id, sub_authority)
  parse_full_record(raw_response, id)
end

#get_full_record(id, sub_authority) ⇒ Object



37
38
39
40
# File 'lib/qa/authorities/oclcts.rb', line 37

def get_full_record(id, sub_authority)
  Deprecation.warn(Oclcts, "get_full_record is deprecated and will be removed in 0.1.0. Use full_record instead", caller)
  full_record(id, sub_authority)
end

#get_raw_response(query_type, id, sub_authority) ⇒ Object



53
54
55
56
# File 'lib/qa/authorities/oclcts.rb', line 53

def get_raw_response(query_type, id, sub_authority)
  query_url = SRU_SERVER_CONFIG["url-pattern"][query_type].gsub("{query}", id).gsub("{id}", id).gsub("{authority-id}", sub_authority)
  Nokogiri::XML(open(query_url))
end

#parse_full_record(raw_xml, id) ⇒ Object



42
43
44
45
46
47
48
49
50
51
# File 'lib/qa/authorities/oclcts.rb', line 42

def parse_full_record(raw_xml, id)
  a = {}
  zthes_record = raw_xml.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|
    if (child.is_a? Nokogiri::XML::Element) && (!child.children.nil?) && (child.children.size == 1) && (child.children.first.is_a? Nokogiri::XML::Text)
      a[child.name] = child.children.first.to_s
    end
  end
  a
end

#search(q, sub_authority = nil) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/qa/authorities/oclcts.rb', line 23

def search(q, sub_authority=nil)
  raw_response = get_raw_response("prefix-query", q, sub_authority)
  r = Array.new
  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