class Qa::LDF::Authority
A Linked Data Fragments-based authority. Access linked data resources through a caching server.
@see LinkedDataFragments::CacheServer
Constants
- DEFAULT_CLIENT
The default linked data fragments client
- DEFAULT_DATASET_NAME
The default linked data fragments client
- DEFAULT_MAPPER
The default mapper
- DEFAULT_SEARCH_SERVICE
The default search service
Attributes
@!attribute [rw] client
@return [Client]
@!attribute [rw] dataset
@return [Symbol] A dataset name (e.g. :lcsh)
@!attribute [rw] mapper
@return [Mapper]
@!attribute [rw] search_service
@return [#search]
@!attribute [rw] client
@return [Client]
@!attribute [rw] dataset
@return [Symbol] A dataset name (e.g. :lcsh)
@!attribute [rw] mapper
@return [Mapper]
@!attribute [rw] search_service
@return [#search]
@!attribute [rw] client
@return [Client]
@!attribute [rw] dataset
@return [Symbol] A dataset name (e.g. :lcsh)
@!attribute [rw] mapper
@return [Mapper]
@!attribute [rw] search_service
@return [#search]
@!attribute [rw] client
@return [Client]
@!attribute [rw] dataset
@return [Symbol] A dataset name (e.g. :lcsh)
@!attribute [rw] mapper
@return [Mapper]
@!attribute [rw] search_service
@return [#search]
Public Class Methods
Gives an authority class for the given namespace.
@param namespace [#to_s] a URI-like namespace string
@return [Authority]
# File lib/qa/ldf/authority.rb, line 38 def for(namespace:) @@namespace_map.fetch(namespace.to_s) { self }.new end
@return [String] gives an empty string for no namespace,
{#for_namespace} returns self in this case
# File lib/qa/ldf/authority.rb, line 45 def namespace '' end
@return [Enumerable<String>]
# File lib/qa/ldf/authority.rb, line 51 def namespaces @@namespace_map.keys end
@yieldparam authority [Authority] self
# File lib/qa/ldf/authority.rb, line 88 def initialize(*) super yield self if block_given? end
Registers a namespace/class pair.
@param namespace [#to_s] a URI-like namespace string @param klass [Class] an authority class
@return [void]
# File lib/qa/ldf/authority.rb, line 62 def register_namespace(namespace:, klass:) @@namespace_map[namespace.to_s] = klass end
Resets the namespaces
@return [void]
# File lib/qa/ldf/authority.rb, line 70 def reset_namespaces @@namespace_map = {} end
Public Instance Methods
@see Qa::Authorities::Base#all
# File lib/qa/ldf/authority.rb, line 95 def all [] end
@return [Qa::LDF::Client]
# File lib/qa/ldf/authority.rb, line 132 def client @client ||= self.class::DEFAULT_CLIENT.new end
@return [Symbol]
# File lib/qa/ldf/authority.rb, line 138 def dataset @dataset ||= self.class::DEFAULT_DATASET_NAME end
Retrieves the given resource's JSON respresentation from the cache server.
The resource is retrieved through the client given by `#client`, and mapped to JSON using `#mapper`.
@see Qa::Authorities::Base#find @see Qa::LDF::Client#get
# File lib/qa/ldf/authority.rb, line 108 def find(id) mapper.map_resource(id, graph(id)) end
@param uri [RDF::URI] @return [RDF::Enumerable]
# File lib/qa/ldf/authority.rb, line 115 def graph(uri) client.get(uri: uri, dataset: dataset) end
@return [JsonMapper]
# File lib/qa/ldf/authority.rb, line 144 def mapper @mapper ||= self.class::DEFAULT_MAPPER.new end
Search the vocabulary
@param query [String] the query string
@return [Array<Hash<Symbol, String>>] the response as a JSON friendly
hash
# File lib/qa/ldf/authority.rb, line 126 def search(query) search_service.search(query) end
@return [#search]
# File lib/qa/ldf/authority.rb, line 150 def search_service @search_service ||= self.class::DEFAULT_SEARCH_SERVICE.new end