Class: Qa::Authorities::Loc
- Inherits:
-
WebServiceBase
- Object
- WebServiceBase
- Qa::Authorities::Loc
- Extended by:
- Deprecation
- Defined in:
- lib/qa/authorities/loc.rb
Instance Attribute Summary
Attributes inherited from WebServiceBase
Class Method Summary collapse
Instance Method Summary collapse
- #find_record_in_response(raw_response, id) ⇒ Object
- #full_record(id, sub_authority) ⇒ Object
- #get_full_record(id, sub_authority) ⇒ Object
-
#initialize ⇒ Loc
constructor
Initialze the Loc class with a query and get the http response from LOC’s server.
- #parse_authority_response(raw_response) ⇒ Object
- #search(q, sub_authority = nil) ⇒ Object
- #sub_authorityURL(sub_authority) ⇒ Object
Methods inherited from WebServiceBase
Constructor Details
#initialize ⇒ Loc
Initialze the Loc class with a query and get the http response from LOC’s server. This is set to a JSON object
9 10 |
# File 'lib/qa/authorities/loc.rb', line 9 def initialize end |
Class Method Details
.authority_valid?(authority) ⇒ Boolean
84 85 86 |
# File 'lib/qa/authorities/loc.rb', line 84 def self.() self..include?() end |
.sub_authorities ⇒ Object
88 89 90 |
# File 'lib/qa/authorities/loc.rb', line 88 def self. ||= .keys end |
.sub_authority_table ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/qa/authorities/loc.rb', line 25 def self. ||= begin vocab_base_url = 'cs%3Ahttp%3A%2F%2Fid.loc.gov%2Fvocabulary%2F' = 'cs%3Ahttp%3A%2F%2Fid.loc.gov%2Fauthorities%2F' datatype_base_url = 'cs%3Ahttp%3A%2F%2Fid.loc.gov%2Fdatatypes%2F' vocab_preservation_base_url = 'cs%3Ahttp%3A%2F%2Fid.loc.gov%2Fvocabulary%2Fpreservation%2F' { 'subjects' => , 'names' => , 'classification' => , 'childrensSubjects' => , 'genreForms' => , 'graphicMaterials' => vocab_base_url, 'organizations' => vocab_base_url, 'relators' => vocab_base_url, 'countries' => vocab_base_url, 'geographicAreas' => vocab_base_url, 'languages' => vocab_base_url, 'iso639-1' => vocab_base_url, 'iso639-2' => vocab_base_url, 'iso639-5' => vocab_base_url, 'edtf' => datatype_base_url, 'preservation' => vocab_base_url, 'actionsGranted' => vocab_base_url, 'agentType' => vocab_base_url, 'contentLocationType' => vocab_preservation_base_url, 'copyrightStatus' => vocab_preservation_base_url, 'cryptographicHashFunctions' => vocab_preservation_base_url, 'environmentCharacteristic' => vocab_preservation_base_url, 'environmentPurpose' => vocab_preservation_base_url, 'eventRelatedAgentRole' => vocab_preservation_base_url, 'eventRelatedObjectRole' => vocab_preservation_base_url, 'eventType' => vocab_preservation_base_url, 'formatRegistryRole' => vocab_preservation_base_url, 'hardwareType' => vocab_preservation_base_url, 'inhibitorTarget' => vocab_preservation_base_url, 'inhibitorType' => vocab_preservation_base_url, 'objectCategory' => vocab_preservation_base_url, 'preservationLevelRole' => vocab_preservation_base_url, 'relationshipSubType' => vocab_preservation_base_url, 'relationshipType' => vocab_preservation_base_url, 'rightsBasis' => vocab_preservation_base_url, 'rightsRelatedAgentRole' => vocab_preservation_base_url, 'signatureEncoding' => vocab_preservation_base_url, 'signatureMethod' => vocab_preservation_base_url, 'softwareType' => vocab_preservation_base_url, 'storageMedium' => vocab_preservation_base_url } end end |
Instance Method Details
#find_record_in_response(raw_response, id) ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/qa/authorities/loc.rb', line 114 def find_record_in_response(raw_response, id) raw_response.each do |single_response| next if single_response[0] != "atom:entry" single_response.each do |result_part| if (result_part[0] == 'atom:title' || result_part[0] == 'atom:id') && id == result_part[2] return single_response end end end return nil end |
#full_record(id, sub_authority) ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/qa/authorities/loc.rb', line 132 def full_record(id, ) search(id, ) full_record = find_record_in_response(@raw_response, id) if full_record.nil? # record not found return {} end parsed_result = {} full_record.each do |section| if section.class == Array label = section[0].split(':').last.to_s case label when 'title', 'id', 'updated', 'created' parsed_result[label] = section[2] when 'link' if section[1]['type'] != nil parsed_result[label + "||#{section[1]['type']}"] = section[1]["href"] else parsed_result[label] = section[1]["href"] end when 'author' = [] #FIXME: Find example with two authors to better understand this data. << section[2][2] parsed_result[label] = end end end parsed_result end |
#get_full_record(id, sub_authority) ⇒ Object
127 128 129 130 |
# File 'lib/qa/authorities/loc.rb', line 127 def get_full_record(id, ) Deprecation.warn(Loc, "get_full_record is deprecated and will be removed in 0.1.0. Use full_record instead", caller) full_record(id, ) end |
#parse_authority_response(raw_response) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/qa/authorities/loc.rb', line 93 def (raw_response) result = [] raw_response.each do |single_response| next if single_response[0] != "atom:entry" id = nil label = '' single_response.each do |result_part| case result_part[0] when 'atom:title' label = result_part[2] when 'atom:id' id = result_part[2] end end id ||= label result << {"id"=>id, "label"=>label} end result end |
#search(q, sub_authority = nil) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/qa/authorities/loc.rb', line 12 def search(q, =nil) if ! (.nil? || Loc..include?()) @raw_response = nil @response = nil return end q += '*' = () query_url = "http://id.loc.gov/search/?q=#{q}&q=#{authority_fragment}&format=json" @raw_response = get_json(query_url) @response = (@raw_response) end |
#sub_authorityURL(sub_authority) ⇒ Object
78 79 80 81 82 |
# File 'lib/qa/authorities/loc.rb', line 78 def () base_url = Loc.[] return "" if base_url.nil? base_url + URI.escape() end |