Class: DataFoodConsortium::Connector::Importer

Inherits:
Object
  • Object
show all
Defined in:
lib/datafoodconsortium/connector/importer.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.prefixed_name(uri) ⇒ Object



23
24
25
# File 'lib/datafoodconsortium/connector/importer.rb', line 23

def self.prefixed_name(uri)
  RDF::URI.new(uri).pname(prefixes: Context.json)
end

.register_type(clazz) ⇒ Object



19
20
21
# File 'lib/datafoodconsortium/connector/importer.rb', line 19

def self.register_type(clazz)
  type_map[clazz::SEMANTIC_TYPE] = clazz
end

.type_mapObject



8
9
10
11
12
13
14
15
16
17
# File 'lib/datafoodconsortium/connector/importer.rb', line 8

def self.type_map
  unless @type_map
    @type_map = {}
    DataFoodConsortium::Connector.semantic_types.each do |type|
      register_type(type)
    end
  end

  @type_map
end

Instance Method Details

#import(json_string_or_io) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/datafoodconsortium/connector/importer.rb', line 27

def import(json_string_or_io)
  @subjects = {}

  graph = parse_rdf(json_string_or_io)
  build_subjects(graph)
  apply_statements(graph)

  if @subjects.size > 1
    @subjects.values
  else
    @subjects.values.first
  end
end