Module: IqRdf

Defined in:
lib/iq_rdf.rb,
lib/iq_rdf/uri.rb,
lib/iq_rdf/node.rb,
lib/iq_rdf/literal.rb,
lib/iq_rdf/version.rb,
lib/iq_rdf/document.rb,
lib/iq_rdf/namespace.rb,
lib/iq_rdf/predicate.rb,
lib/iq_rdf/blank_node.rb,
lib/iq_rdf/collection.rb,
lib/iq_rdf/literal/uri.rb,
lib/iq_rdf/literal/string.rb,
lib/iq_rdf/literal/boolean.rb,
lib/iq_rdf/literal/numeric.rb,
lib/iq_rdf/predicate_namespace.rb

Overview

Copyright 2011 innoQ Deutschland GmbH

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Defined Under Namespace

Modules: TestModule Classes: BlankNode, Collection, Document, Literal, Namespace, Node, Predicate, PredicateNamespace, Uri

Constant Summary collapse

VERSION =
"0.2.0"

Class Method Summary collapse

Class Method Details

.build_full_uri_subject(uri, type = nil, &block) ⇒ Object



75
76
77
78
# File 'lib/iq_rdf.rb', line 75

def self.build_full_uri_subject(uri, type = nil, &block)
  raise "Parameter uri has to be an URI" unless uri.is_a?(URI)
  Namespace.dummy_empty_namespace.build_uri(uri, type, &block)
end

.find_or_create_namespace_class(klass_name) ⇒ Object



80
81
82
83
84
85
86
# File 'lib/iq_rdf.rb', line 80

def self.find_or_create_namespace_class(klass_name)
  if RUBY_VERSION < "1.9"
    self.const_defined?(klass_name) ? self.const_get(klass_name) : self.const_set(klass_name, Class.new(IqRdf::Namespace))
  else
    self.const_defined?(klass_name, false) ? self.const_get(klass_name, false) : self.const_set(klass_name, Class.new(IqRdf::Namespace))
  end
end

.method_missing(method_name, *args, &block) ⇒ Object

A shortcut so be able to define Subjects and Objects without specifing a namespace. When no namespace is given, Default will be used.

Example:

IqRdf::sub.pred(IqRdf::obj) # => :sub :pred :obj.


71
72
73
# File 'lib/iq_rdf.rb', line 71

def self.method_missing(method_name, *args, &block)
  IqRdf::Default.send(method_name, *args, &block)
end

.rails_template(template, source = nil) ⇒ Object

Copyright 2011 innoQ Deutschland GmbH

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/iq_rdf/rails/iq_rdf.rb', line 15

def IqRdf.rails_template(template, source = nil)
  source ||= template.source

  <<-EOV
  document = IqRdf::Document.new()
  #{source}
  if params[:format].to_s == "ttl"
    controller.response.headers["Content-Type"] ||= 'text/turtle;charset=utf-8'
    document.to_turtle
  elsif  params[:format].to_s == "nt"
    controller.response.headers["Content-Type"] ||= 'text/plain;charset=utf-8'
    document.to_ntriples
  elsif params[:format].to_s == "rdf"
    controller.response.headers["Content-Type"] ||= 'application/xml+rdf;charset=utf-8'
    document.to_xml
  else # Default => turtle
    controller.response.headers["Content-Type"] ||= 'text/turtle;charset=utf-8'
    document.to_turtle
  end
  EOV
end

.use(&block) ⇒ Object

This evals the given block in the context of IqRdF. You can use this to be able to omit the “IqRdf::” in your turtle statements.

Example:

IqRdf::use do
  mySubject Rdf::type Skos::Concept # => mySubject rdf:type skos:Concept
end

But: There is an inconsistency in Ruby 1.8 and JRuby <= 1.4 (even with –1.9):

module M; end
M.module_eval {C = 1; self::D = 1}
p defined? M::C # => nil (should be "constant" (and is in C Ruby 1.9))
p defined? M::D # => "constant"

This means, that use will only work with Ruby 1.9. Feel free to change this if you know another way then module_eval to achieve this.

Raises:

  • (NotImplementedError)


61
62
63
64
# File 'lib/iq_rdf.rb', line 61

def self.use(&block)
  raise NotImplementedError, "This is not supported in your Ruby version." unless defined?(TestModule::TEST_CONST)
  self.module_eval(&block)
end