Class: Qa::LDF::Model
- Inherits:
-
Object
- Object
- Qa::LDF::Model
- Includes:
- ActiveTriples::RDFSource
- Defined in:
- lib/qa/ldf/model.rb
Overview
A base model for validatable authority values.
Class Method Summary collapse
-
.from_graph(uri:, graph:) ⇒ Qa::LDF::Model
Builds a model from the graph.
-
.from_qa_result(qa_result:) ⇒ Qa::LDF::Model
Builds a model from a QA result hash.
Instance Method Summary collapse
- #authority ⇒ Qa::LDF::Authority
-
#authority_namespace ⇒ String
The namespace for the authority used by this model instance.
-
#fetch ⇒ Object
Fetches from the cache client.
- #lang_label(language: :en) ⇒ Object
Class Method Details
.from_graph(uri:, graph:) ⇒ Qa::LDF::Model
Builds a model from the graph.
88 89 90 |
# File 'lib/qa/ldf/model.rb', line 88 def from_graph(uri:, graph:) new(uri) << graph end |
.from_qa_result(qa_result:) ⇒ Qa::LDF::Model
TODO:
Make ActiveTriples::RDFSource#default_labels public or protected.
Builds a model from a QA result hash.
109 110 111 112 113 114 115 116 |
# File 'lib/qa/ldf/model.rb', line 109 def from_qa_result(qa_result:) qa_result.dup model = new(qa_result.delete(:id.to_s)) model.set_value(model.send(:default_labels).first, qa_result.delete(:label.to_s)) model end |
Instance Method Details
#authority ⇒ Qa::LDF::Authority
24 25 26 |
# File 'lib/qa/ldf/model.rb', line 24 def Qa::LDF::Authority.for(namespace: ) end |
#authority_namespace ⇒ String
Returns the namespace for the authority used by this model instance.
43 44 45 46 47 48 49 |
# File 'lib/qa/ldf/model.rb', line 43 def return Qa::LDF::Authority.namespace if node? Qa::LDF::Authority .namespaces .find { |ns| to_uri.start_with?(ns) } end |
#fetch ⇒ Object
Fetches from the cache client.
55 56 57 58 59 60 61 62 |
# File 'lib/qa/ldf/model.rb', line 55 def fetch insert(.graph(to_uri)) rescue => e raise e unless block_given? yield(self) ensure self end |
#lang_label(language: :en) ⇒ Object
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/qa/ldf/model.rb', line 70 def lang_label(language: :en) labels = rdf_label label = labels.find do |literal| literal.respond_to?(:language) && literal.language == language end return labels.first unless label label end |