Module: OpenBEL::Model::ClassMethods

Defined in:
lib/openbel/api/model/rdf_resource.rb

Instance Method Summary collapse

Instance Method Details

#from(statements) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/openbel/api/model/rdf_resource.rb', line 11

def from(statements)
  obj = self.new
  statements.each do |sub, pred, obj_val|
    index = pred.rindex('#') || pred.rindex('/')
    if index
      attribute = pred[index+1..-1]

      # handle type statement
      if attribute == 'type'
        # ... the URI
        if obj.respond_to?(:uri=)
          obj.send(:uri=, sub)
        end
        # ... the BEL vocabulary type
        if obj_val.start_with?(VOCABULARY_RDF) and obj.respond_to?(:type=)
          obj.send(:type=, obj_val)
          next
        end
      end
      if obj.respond_to? :"#{attribute}="
        obj.send(:"#{attribute}=", obj_val)
      end
    else
      $stderr.puts "cannot parse local name for #{pred}"
    end
  end
  (obj.respond_to? :uri and obj.uri) ? obj : nil
end