Class: Qa::Authorities::Oclcts
- 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
-
#sub_authority ⇒ Object
Returns the value of attribute sub_authority.
Class Method Summary collapse
Instance Method Summary collapse
- #full_record(id, sub_authority) ⇒ Object
- #get_full_record(id, sub_authority) ⇒ Object
- #get_raw_response(query_type, id, sub_authority) ⇒ Object
-
#initialize ⇒ Oclcts
constructor
A new instance of Oclcts.
- #parse_full_record(raw_xml, id) ⇒ Object
- #search(q, sub_authority = nil) ⇒ Object
Constructor Details
#initialize ⇒ Oclcts
Returns a new instance of Oclcts.
12 13 |
# File 'lib/qa/authorities/oclcts.rb', line 12 def initialize end |
Instance Attribute Details
#sub_authority ⇒ Object
Returns the value of attribute sub_authority.
10 11 12 |
# File 'lib/qa/authorities/oclcts.rb', line 10 def end |
Class Method Details
.authority_valid?(sub_authority) ⇒ Boolean
15 16 17 |
# File 'lib/qa/authorities/oclcts.rb', line 15 def self.() self..include?() end |
.sub_authorities ⇒ Object
19 20 21 |
# File 'lib/qa/authorities/oclcts.rb', line 19 def self. ||= SRU_SERVER_CONFIG["authorities"].map { || [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, ) raw_response = get_raw_response("id-lookup", id, ) 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, ) Deprecation.warn(Oclcts, "get_full_record is deprecated and will be removed in 0.1.0. Use full_record instead", caller) full_record(id, ) 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, ) query_url = SRU_SERVER_CONFIG["url-pattern"][query_type].gsub("{query}", id).gsub("{id}", id).gsub("{authority-id}", ) 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, =nil) raw_response = get_raw_response("prefix-query", q, ) 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 |