Class: Note::SKOS::Base

Inherits:
Base
  • Object
show all
Defined in:
app/models/note/skos/base.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.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.build_from_rdf(subject, predicate, object) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/models/note/skos/base.rb', line 21

def self.build_from_rdf(subject, predicate, object)
  unless subject.class.reflections.include?(self.name.to_relation_name)
    raise "Note::SKOS::Base#build_from_rdf: Subject (#{subject}) must be able to recieve this kind of notes (#{self.class.name} => #{self.class.name.to_relation_name})."
  end
  unless object =~ /^"(.+)"(@(.+))$/
    raise "Note::SKOS::Base#build_from_rdf: Object (#{object}) must be a string literal"
  end

  lang = $3
  value = JSON.parse(%Q{["#{$1}"]})[0].gsub("\\n", "\n") # Trick to decode \uHHHHH chars

  subject.send(self.name.to_relation_name) << self.new(:value => value, :language => lang)
end

Instance Method Details

#build_rdf(document, subject) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/models/note/skos/base.rb', line 35

def build_rdf(document, subject)
  ns, id = "", ""
  if (self.rdf_namespace && self.rdf_predicate)
    ns, id = self.rdf_namespace, self.rdf_predicate
  elsif self.class == Note::SKOS::Base # This could be done by setting self.rdf_predicate to 'note'. But all subclasses would inherit this value.
    ns, id = "Skos", "note"
  else
    raise "Note::SKOS::Base#build_rdf: Class #{self.class.name} needs to define self.rdf_namespace and self.rdf_predicate."
  end

  if (IqRdf::Namespace.find_namespace_class(ns))
    subject.send(ns).send(id, value, :lang => language)
  else
    raise "Note::SKOS::Base#build_rdf: couldn't find Namespace '#{ns}'."
  end
end