Class: Qa::LDF::Authority

Inherits:
Authorities::Base
  • Object
show all
Defined in:
lib/qa/ldf/authority.rb

Overview

A Linked Data Fragments-based authority. Access linked data resources through a caching server.

See Also:

  • LinkedDataFragments::CacheServer

Direct Known Subclasses

FAST, LCNames

Constant Summary collapse

DEFAULT_DATASET_NAME =

The default linked data fragments client

:''
DEFAULT_CLIENT =

The default linked data fragments client

Qa::LDF::Client
DEFAULT_MAPPER =

The default mapper

Qa::LDF::JsonMapper
DEFAULT_SEARCH_SERVICE =

The default search service

Qa::LDF::EmptySearchService
@@namespace_map =
{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|authority| ... } ⇒ Authority

Returns a new instance of Authority.

Yield Parameters:



88
89
90
91
# File 'lib/qa/ldf/authority.rb', line 88

def initialize(*)
  super
  yield self if block_given?
end

Instance Attribute Details

#clientQa::LDF::Client

Returns:



84
# File 'lib/qa/ldf/authority.rb', line 84

attr_writer :client, :dataset, :mapper, :search_service

#datasetSymbol

Returns:

  • (Symbol)


84
# File 'lib/qa/ldf/authority.rb', line 84

attr_writer :client, :dataset, :mapper, :search_service

#mapperJsonMapper

Returns:



84
# File 'lib/qa/ldf/authority.rb', line 84

attr_writer :client, :dataset, :mapper, :search_service

#search_service#search

Returns:



84
# File 'lib/qa/ldf/authority.rb', line 84

attr_writer :client, :dataset, :mapper, :search_service

Class Method Details

.for(namespace:) ⇒ Authority

Gives an authority class for the given namespace.

Parameters:

  • namespace (#to_s)

    a URI-like namespace string

Returns:



38
39
40
# File 'lib/qa/ldf/authority.rb', line 38

def for(namespace:)
  @@namespace_map.fetch(namespace.to_s) { self }.new
end

.namespaceString

Returns gives an empty string for no namespace, #for_namespace returns self in this case.

Returns:

  • (String)

    gives an empty string for no namespace, #for_namespace returns self in this case



45
46
47
# File 'lib/qa/ldf/authority.rb', line 45

def namespace
  ''
end

.namespacesEnumerable<String>

Returns:

  • (Enumerable<String>)


51
52
53
# File 'lib/qa/ldf/authority.rb', line 51

def namespaces
  @@namespace_map.keys
end

.register_namespace(namespace:, klass:)

This method returns an undefined value.

Registers a namespace/class pair.

Parameters:

  • namespace (#to_s)

    a URI-like namespace string

  • klass (Class)

    an authority class



62
63
64
# File 'lib/qa/ldf/authority.rb', line 62

def register_namespace(namespace:, klass:)
  @@namespace_map[namespace.to_s] = klass
end

.reset_namespaces

This method returns an undefined value.

Resets the namespaces



70
71
72
# File 'lib/qa/ldf/authority.rb', line 70

def reset_namespaces
  @@namespace_map = {}
end

Instance Method Details

#allObject

See Also:

  • Authorities::Base#all


95
96
97
# File 'lib/qa/ldf/authority.rb', line 95

def all
  []
end

#find(id) ⇒ Object

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 Also:



108
109
110
# File 'lib/qa/ldf/authority.rb', line 108

def find(id)
  mapper.map_resource(id, graph(id))
end

#graph(uri) ⇒ RDF::Enumerable

Parameters:

  • uri (RDF::URI)

Returns:

  • (RDF::Enumerable)


115
116
117
# File 'lib/qa/ldf/authority.rb', line 115

def graph(uri)
  client.get(uri: uri, dataset: dataset)
end

#search(query) ⇒ Array<Hash<Symbol, String>>

Search the vocabulary

Parameters:

  • query (String)

    the query string

Returns:

  • (Array<Hash<Symbol, String>>)

    the response as a JSON friendly hash



126
127
128
# File 'lib/qa/ldf/authority.rb', line 126

def search(query)
  search_service.search(query)
end