Class: RDF::Oxigraph::Reader

Inherits:
Reader
  • Object
show all
Defined in:
lib/rdf/oxigraph/format.rb

Overview

Batch RDF::Reader backed by oxigraph's native parsers. Subclasses set the oxigraph format via oxigraph_format.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input = $stdin, **options, &block) ⇒ Reader

Returns a new instance of Reader.



31
32
33
34
# File 'lib/rdf/oxigraph/format.rb', line 31

def initialize(input = $stdin, **options, &block)
  @content = input.respond_to?(:read) ? input.read : input.to_s
  super
end

Class Method Details

.oxigraph_format(value = nil) ⇒ Object



26
27
28
29
# File 'lib/rdf/oxigraph/format.rb', line 26

def self.oxigraph_format(value = nil)
  @oxigraph_format = value unless value.nil?
  @oxigraph_format
end

Instance Method Details

#each_statementObject Also known as: each



36
37
38
39
40
41
# File 'lib/rdf/oxigraph/format.rb', line 36

def each_statement
  return enum_for(:each_statement) unless block_given?
  RDF::Oxigraph.parse(@content, self.class.oxigraph_format).each do |quad|
    yield Conversion.deserialize_statement(quad)
  end
end

#each_tripleObject



44
45
46
47
# File 'lib/rdf/oxigraph/format.rb', line 44

def each_triple
  return enum_for(:each_triple) unless block_given?
  each_statement { |st| yield(st.subject, st.predicate, st.object) }
end