class Qa::LDF::Model
A base model for validatable authority values.
Public Class Methods
from_graph(uri:, graph:)
click to toggle source
Builds a model from the graph.
@param graph [RDF::Graph]
@return [Qa::LDF::Model] the built model
# File lib/qa/ldf/model.rb, line 88 def from_graph(uri:, graph:) new(uri) << graph end
from_qa_result(qa_result:)
click to toggle source
Builds a model from a QA result hash.
@example
model = Qa::LDF::Model.from_qa_result(id: 'http://example.com/moomin', label: 'Moomin' model.to_uri # => #<RDF::URI:0x... URI:http://example.com/moomin> model.rdf_label # => ['Moomin']
@param qa_result [Hash<Symbol, String>]
@return [Qa::LDF::Model] the built model
@todo Make ActiveTriples::RDFSource#default_labels public or
protected.
# 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
Public Instance Methods
fetch() { |self| ... }
click to toggle source
Fetches from the cache client.
@see ActiveTriples::RDFSource#fetch
# File lib/qa/ldf/model.rb, line 55 def fetch insert(authority.graph(to_uri)) rescue => e raise e unless block_given? yield(self) ensure self end
lang_label(language: :en)
click to toggle source
@param language [Symbol] a two letter (BCP47) language tag.
@see ActiveTriples::RDFSource.rdf_label @see www.w3.org/TR/rdf11-concepts/#section-Graph-Literal @see tools.ietf.org/html/bcp47
# 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