Class: Qa::Authorities::Oclcts
- Inherits:
-
Base
- Object
- Base
- Qa::Authorities::Oclcts
show all
- 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
Attributes inherited from Base
#query_url, #raw_response, #response
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(q, sub_authority = '') ⇒ Oclcts
Returns a new instance of Oclcts.
11
12
13
14
15
|
# File 'lib/qa/authorities/oclcts.rb', line 11
def initialize(q, sub_authority='')
self.sub_authority = sub_authority
self.query_url = SRU_SERVER_CONFIG["url-pattern"]["prefix-query"].gsub(/\{query\}/, q).gsub(/\{authority\-id\}/, sub_authority)
self.raw_response = Nokogiri::XML(open(self.query_url))
end
|
Instance Attribute Details
#sub_authority ⇒ Object
Returns the value of attribute sub_authority.
9
10
11
|
# File 'lib/qa/authorities/oclcts.rb', line 9
def sub_authority
@sub_authority
end
|
Class Method Details
.authority_valid?(sub_authority) ⇒ Boolean
17
18
19
|
# File 'lib/qa/authorities/oclcts.rb', line 17
def self.authority_valid?(sub_authority)
sub_authorities.include?(sub_authority)
end
|
.sub_authorities ⇒ Object
21
22
23
24
25
26
27
|
# File 'lib/qa/authorities/oclcts.rb', line 21
def self.sub_authorities
a = []
SRU_SERVER_CONFIG["authorities"].each do | sub_authority |
a.append(sub_authority[0])
end
a
end
|
Instance Method Details
#get_full_record(id) ⇒ Object
37
38
39
40
41
42
43
44
45
|
# File 'lib/qa/authorities/oclcts.rb', line 37
def get_full_record(id)
unless self.raw_response.xpath("sru:searchRetrieveResponse/sru:records/sru:record/sru:recordData/Zthes/term[termId='" + id + "']", 'sru' => 'http://www.loc.gov/zing/srw/').blank?
parse_full_record(self.raw_response, id)
else
url = SRU_SERVER_CONFIG["url-pattern"]["id-lookup"].gsub(/\{id\}/, id).gsub(/\{authority\-id\}/, self.sub_authority)
parse_full_record(Nokogiri::XML(open(url)), id)
end
end
|
#parse_authority_response ⇒ Object
29
30
31
32
33
34
35
|
# File 'lib/qa/authorities/oclcts.rb', line 29
def parse_authority_response
r = Array.new
self.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
self.response = r
end
|
#parse_full_record(raw_xml, id) ⇒ Object
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/qa/authorities/oclcts.rb', line 47
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
|
#results ⇒ Object
58
59
60
|
# File 'lib/qa/authorities/oclcts.rb', line 58
def results
self.response.to_json
end
|