Class: RDF::Reader

Inherits:
Object
  • Object
show all
Defined in:
lib/rdf/reader.rb

Class Method Summary collapse

Class Method Details

.gzopen(filename, options = {}) {|reader| ... } ⇒ Object

Parses input from the given gzip file name or URL.

any additional options (see #initialize and Format.for)

Parameters:

  • filename (String, #to_s)
  • options (Hash{Symbol => Object}) (defaults to: {})

Options Hash (options):

  • :format (Symbol) — default: :ntriples

Yields:

  • (reader)

Yield Parameters:

Yield Returns:

  • (void)

    ignored

Raises:

  • (RDF::FormatError)

    if no reader found for the specified format



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/rdf/reader.rb', line 14

def self.gzopen(filename, options = {}, &block)
  Util::File.open_gzipfile(filename, options) do |file|
    format_options = options.dup
    format_options[:content_type] ||= file.content_type if file.respond_to?(:content_type)
    format_options[:file_name] ||= filename
    reader = self.for(format_options[:format] || format_options) do
      # Return a sample from the input file
      sample = file.read(1000)
      file.rewind
      sample
    end
    if reader
      reader.new(file, options, &block)
    else
      raise FormatError, "unknown RDF format: #{format_options.inspect}"
    end
  end
end