Class: RDF::Raptor::CLI::Writer

Inherits:
Writer
  • Object
show all
Defined in:
lib/rdf/raptor/cli.rb

Overview

CLI writer implementation.

Instance Method Summary collapse

Constructor Details

#initialize(output = $stdout, base_uri: nil, **options) {|writer| ... } ⇒ Writer

Initializes the CLI writer instance.

Parameters:

  • output (IO, File) (defaults to: $stdout)
  • options (Hash{Symbol => Object}) —

    any additional options (see RDF::Writer#initialize)

Yields:

  • (writer) —

    self

Yield Parameters:

  • writer (RDF::Writer)

Yield Returns:

  • (void)

Raises:

  • (RDF::WriterError)


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, **options, &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 options.has_key?(:base_uri)
      @rapper  = IO.popen(@command, 'rb+')
    else
      raise ArgumentError, "unsupported output type: #{output.inspect}"
  end
  @writer = RDF::NTriples::Writer.new(@rapper, **options)
  super(output, base_uri: base_uri, **options, &block)
end