Module: Spread2RDF::Namespace

Defined in:
lib/spread2rdf/namespace.rb

Constant Summary collapse

DEFAULTS =
{
    UNIT: ::RDF::Vocabulary.new('http://qudt.org/vocab/unit#')
}

Class Method Summary collapse

Class Method Details

.[](name) ⇒ Object



8
9
10
11
12
13
# File 'lib/spread2rdf/namespace.rb', line 8

def [](name)
  name = name.to_sym
  self.namespace[name] ||
      ( RDF.const_defined?(name) && RDF.const_get(name)) ||
      nil
end

.[]=(name, namespace) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/spread2rdf/namespace.rb', line 15

def []=(name, namespace)
  name = name.to_sym
  self.namespace[name] = case namespace
    when RDF::Vocabulary          then namespace
    when String, RDF::URI         then RDF::Vocabulary.new(namespace)
    else raise ArgumentError, "expecting a namespace but got #{namespace}:#{namespace.class}"
  end
end

.const_missing(name) ⇒ Object



43
44
45
# File 'lib/spread2rdf/namespace.rb', line 43

def const_missing(name)
  self[name] or super
end

.namespaceObject



24
25
26
# File 'lib/spread2rdf/namespace.rb', line 24

def namespace
  @namespace ||= DEFAULTS
end

.namespacesObject



28
29
30
# File 'lib/spread2rdf/namespace.rb', line 28

def namespaces
  namespace.values
end

.resolve_to_namespace(namespace_descriptor) ⇒ Object



32
33
34
35
36
37
38
39
40
41
# File 'lib/spread2rdf/namespace.rb', line 32

def resolve_to_namespace(namespace_descriptor)
  case namespace_descriptor
    when Symbol
      Namespace[namespace_descriptor]
    when RDF::Vocabulary, RDF::URI, String
      namespace_descriptor.to_s
    else
      raise "invalid namespace: #{namespace_descriptor.inspect}:#{namespace_descriptor.class}"
  end
end