Class: RDF::Raptor::CLI::Writer
- Inherits:
-
Writer
- Object
- Writer
- RDF::Raptor::CLI::Writer
- Defined in:
- lib/rdf/raptor/cli.rb
Overview
CLI writer implementation.
Instance Method Summary collapse
-
#initialize(output = $stdout, base_uri: nil, **options) {|writer| ... } ⇒ Writer
constructor
Initializes the CLI writer instance.
-
#output_transit(may_block)
protected
Feeds any available
rapper
output to the destination. - #write_epilogue protected
- #write_prologue protected
- #write_triple(subject, predicate, object) protected
Constructor Details
#initialize(output = $stdout, base_uri: nil, **options) {|writer| ... } ⇒ Writer
Initializes the CLI writer instance.
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/rdf/raptor/cli.rb', line 138 def initialize(output = $stdout, base_uri: nil, **, &block) raise RDF::WriterError, "`rapper` binary not found" unless RDF::Raptor.available? format = self.class.format.rapper_format case output when File, IO, StringIO, Tempfile @command = "#{RAPPER} -q -i turtle -o #{format} file:///dev/stdin" @command << " '#{base_uri}'" if .has_key?(:base_uri) @rapper = IO.popen(@command, 'rb+') else raise ArgumentError, "unsupported output type: #{output.inspect}" end @writer = RDF::NTriples::Writer.new(@rapper, **) super(output, base_uri: base_uri, **, &block) end |
Instance Method Details
#output_transit(may_block) (protected)
This method returns an undefined value.
Feeds any available rapper
output to the destination.
188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/rdf/raptor/cli.rb', line 188 def output_transit(may_block) unless @rapper.closed? chunk_size = @options[:chunk_size] || 4096 # bytes begin loop do @output.write(may_block ? @rapper.sysread(chunk_size) : @rapper.read_nonblock(chunk_size)) end rescue EOFError => e @rapper.close rescue Errno::EAGAIN, Errno::EINTR # eat end end end |
#write_epilogue (protected)
This method returns an undefined value.
178 179 180 181 |
# File 'lib/rdf/raptor/cli.rb', line 178 def write_epilogue @rapper.close_write unless @rapper.closed? output_transit(true) end |
#write_prologue (protected)
This method returns an undefined value.
159 160 161 |
# File 'lib/rdf/raptor/cli.rb', line 159 def write_prologue super end |
#write_triple(subject, predicate, object) (protected)
This method returns an undefined value.
169 170 171 172 173 |
# File 'lib/rdf/raptor/cli.rb', line 169 def write_triple(subject, predicate, object) output_transit(false) @writer.write_triple(subject, predicate, object) output_transit(false) end |