Class: RDF::Raptor::CLI::Reader
- Inherits:
-
RDF::Reader
- Object
- RDF::Reader
- RDF::Raptor::CLI::Reader
- Defined in:
- lib/rdf/raptor/cli.rb
Overview
CLI reader implementation.
Defined Under Namespace
Modules: Extensions
Instance Method Summary collapse
-
#initialize(input = $stdin, base_uri: nil, **options) {|reader| ... } ⇒ Reader
constructor
Initializes the CLI reader instance.
Constructor Details
#initialize(input = $stdin, base_uri: nil, **options) {|reader| ... } ⇒ Reader
Initializes the CLI reader instance.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/rdf/raptor/cli.rb', line 36 def initialize(input = $stdin, base_uri: nil, **, &block) raise RDF::ReaderError, "`rapper` binary not found" unless RDF::Raptor.available? format = self.class.format.rapper_format case input when RDF::URI, %r(^(file|http|https|ftp)://) @command = "#{RAPPER} -q -i #{format} -o ntriples '#{input}'" @command << " '#{base_uri}'" if .has_key?(:base_uri) @rapper = IO.popen(@command, 'rb') when File, Tempfile @command = "#{RAPPER} -q -i #{format} -o ntriples '#{File.(input.path)}'" @command << " '#{base_uri}'" if .has_key?(:base_uri) @rapper = IO.popen(@command, 'rb') else # IO, String @command = "#{RAPPER} -q -i #{format} -o ntriples file:///dev/stdin" @command << " '#{base_uri}'" if .has_key?(:base_uri) @rapper = IO.popen(@command, 'rb+') pid = fork do # process to feed `rapper` begin @rapper.close_read if input.respond_to?(:read) buf = String.new while input.read(8192, buf) @rapper.write(buf) end else @rapper.write(input.to_s) end @rapper.close_write ensure Process.exit end end Process.detach(pid) @rapper.close_write end @options = @reader = RDF::NTriples::Reader.new(@rapper, @options).extend(Extensions) if block_given? case block.arity when 0 then instance_eval(&block) else block.call(self) end end end |