Class: Qa::Authorities::Oclcts
- 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
- #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.
11 12 |
# File 'lib/qa/authorities/oclcts.rb', line 11 def initialize 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 end |
Class Method Details
.authority_valid?(sub_authority) ⇒ Boolean
14 15 16 |
# File 'lib/qa/authorities/oclcts.rb', line 14 def self.() self..include?() end |
.sub_authorities ⇒ Object
18 19 20 |
# File 'lib/qa/authorities/oclcts.rb', line 18 def self. @sub_authorities ||= SRU_SERVER_CONFIG["authorities"].map { || [0] } end |
Instance Method Details
#get_full_record(id, sub_authority) ⇒ Object
31 32 33 34 |
# File 'lib/qa/authorities/oclcts.rb', line 31 def get_full_record(id, ) raw_response = get_raw_response("id-lookup", id, ) parse_full_record(raw_response, id) end |
#get_raw_response(query_type, id, sub_authority) ⇒ Object
47 48 49 50 |
# File 'lib/qa/authorities/oclcts.rb', line 47 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
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/qa/authorities/oclcts.rb', line 36 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
22 23 24 25 26 27 28 29 |
# File 'lib/qa/authorities/oclcts.rb', line 22 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 |