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)
-
- (Reader) initialize(input = $stdin, options = {}) {|reader| ... }
constructor
Initializes the CLI reader instance.
- - (Array(RDF::Resource, RDF::URI, RDF::Term)) read_triple protected
Constructor Details
- (Reader) initialize(input = $stdin, options = {}) {|reader| ... }
Initializes the CLI reader instance.
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 86 |
# File 'lib/rdf/raptor/cli.rb', line 37 def initialize(input = $stdin, = {}, &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 |
Instance Method Details
- (Array(RDF::Resource, RDF::URI, RDF::Term)) read_triple (protected)
93 94 95 96 97 98 99 100 101 102 |
# File 'lib/rdf/raptor/cli.rb', line 93 def read_triple raise EOFError if @rapper.closed? begin triple = @reader.read_triple rescue EOFError @rapper.close raise end triple end |