Class: Tripleloop::Extractor

Inherits:
Object
  • Object
show all
Defined in:
lib/tripleloop/extractor.rb

Defined Under Namespace

Classes: BrokenMappingError

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context) ⇒ Extractor

Returns a new instance of Extractor.



2
3
4
5
# File 'lib/tripleloop/extractor.rb', line 2

def initialize(context)
  @context = context
  bind_variables!
end

Class Method Details

.bind(name, &block) ⇒ Object



17
18
19
20
# File 'lib/tripleloop/extractor.rb', line 17

def self.bind(name, &block)
  @extractor_bindings ||= {}
  @extractor_bindings[name.to_sym] = block
end

.fragment_mapObject



22
23
24
# File 'lib/tripleloop/extractor.rb', line 22

def self.fragment_map
  @fragment_map || {}
end

.map(*fragment, &block) ⇒ Object



12
13
14
15
# File 'lib/tripleloop/extractor.rb', line 12

def self.map(*fragment, &block)
  @fragment_map ||= {}
  @fragment_map.merge!(fragment => block)
end

Instance Method Details

#extractObject



26
27
28
29
30
31
32
33
34
# File 'lib/tripleloop/extractor.rb', line 26

def extract
  self.class.fragment_map.reduce([]) do |accu, (path, block)|
    if fragment = Tripleloop::Util.with_nested_fetch(context).get_in(*path)
      add_to_triples(accu, fragment, &block)
    else
      accu
    end
  end
end

#nameObject



7
8
9
10
# File 'lib/tripleloop/extractor.rb', line 7

def name
  class_name = self.class.name.split('::').last
  Tripleloop::Util::String.snake_case(class_name).gsub(/_extractor$/,'')
end