Module: LinkedVocabs::Controlled::ClassMethods

Defined in:
lib/linked_vocabs/controlled.rb

Overview

Class methods for adding and using controlled vocabularies

Defined Under Namespace

Classes: QaRDF

Instance Method Summary collapse

Instance Method Details

#list_termsArray<RDF::URI>

Note: this does not necessarily list *all the term* allowable by the class. Non-strict RDF::Vocabularies are not included in this method’s output.

Returns:

  • (Array<RDF::URI>)

    terms allowable by the registered StrictVocabularies



93
94
95
96
97
98
99
100
# File 'lib/linked_vocabs/controlled.rb', line 93

def list_terms
  terms = []
  vocabularies.each do |vocab, config|
    next unless config[:class].respond_to? :properties
    terms += config[:class].properties.select { |s| s.start_with? config[:class].to_s }
  end
  terms
end

#load_vocabulariesObject

Gets data for all vocabularies used and loads it into the configured repository. After running this new (and reloaded) RdfResource objects of this class will have data from their source web document.



107
108
109
110
111
# File 'lib/linked_vocabs/controlled.rb', line 107

def load_vocabularies
  vocabularies.each do |name, config|
    load_vocab(name)
  end
end

#qa_interfaceObject



120
121
122
# File 'lib/linked_vocabs/controlled.rb', line 120

def qa_interface
  @qa_interface ||= QaRDF.new(self)
end

#use_vocabulary(name, opts = {}) ⇒ Object



76
77
78
79
80
81
# File 'lib/linked_vocabs/controlled.rb', line 76

def use_vocabulary(name, opts={})
  raise ControlledVocabularyError, "Vocabulary undefined: #{name.to_s.upcase}" unless LinkedVocabs.vocabularies.include? name
  opts[:class] = name_to_class(name) unless opts.include? :class
  opts.merge! LinkedVocabs.vocabularies[name.to_sym]
  vocabularies[name] = opts
end

#uses_vocab_prefix?(str) ⇒ Boolean

Returns:

  • (Boolean)


113
114
115
116
117
118
# File 'lib/linked_vocabs/controlled.rb', line 113

def uses_vocab_prefix?(str)
  vocabularies.each do |vocab, config|
    return true if str.start_with? config[:prefix]
  end
  false
end

#vocabulariesObject



83
84
85
# File 'lib/linked_vocabs/controlled.rb', line 83

def vocabularies
  @vocabularies ||= {}.with_indifferent_access
end