Sha256: f133baa57a37b022299cbbd0c2f9da60258536d7b8adf09f4ae66f2bcf967c7a

Contents?: true

Size: 1.46 KB

Versions: 12

Compression:

Stored size: 1.46 KB

Contents

require 'rdf/turtle/terminals'

module RDF::Turtle
  ##
  # Streaming writer interface
  # @author [Gregg Kellogg](http://greggkellogg.net/)
  module StreamingWriter
    ##
    # Write out declarations
    # @return [void] `self`
    def stream_prologue
      if @options[:standard_prefixes]
        RDF::Vocabulary.each do |vocab|
          pfx = vocab.__name__.to_s.split('::').last.downcase
          prefix(pfx, vocab.to_uri)
        end
      end
      preprocess
      start_document
      @output.puts ""
      self
    end

    ##
    # Write out a statement, retaining current
    # `subject` and `predicate` to create more compact output
    # @return [void] `self`
    def stream_statement(statement)
      if statement.subject != @streaming_subject
        @output.puts ' .' if @streaming_subject
        @streaming_subject, @streaming_predicate = statement.subject, statement.predicate
        @output.write "#{format_term(statement.subject)} "
        @output.write "#{format_term(statement.predicate)} "
      elsif statement.predicate != @streaming_predicate
        @streaming_predicate = statement.predicate
        @output.write ";\n#{indent(1)}#{format_term(statement.predicate)} "
      else
        @output.write ",\n#{indent(2)}"
      end
      @output.write("#{format_term(statement.object)}")
    end

    ##
    # Complete open statements
    # @return [void] `self`
    def stream_epilogue
      @output.puts ' .' if @streaming_subject
    end

    private
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
rdf-turtle-1.1.7 lib/rdf/turtle/streaming_writer.rb
rdf-turtle-1.1.6 lib/rdf/turtle/streaming_writer.rb
rdf-turtle-1.1.5 lib/rdf/turtle/streaming_writer.rb
rdf-turtle-1.1.4 lib/rdf/turtle/streaming_writer.rb
rdf-turtle-1.1.3.1 lib/rdf/turtle/streaming_writer.rb
rdf-turtle-1.1.3 lib/rdf/turtle/streaming_writer.rb
rdf-turtle-1.1.2 lib/rdf/turtle/streaming_writer.rb
rdf-turtle-1.1.1 lib/rdf/turtle/streaming_writer.rb
rdf-turtle-1.1.0.1 lib/rdf/turtle/streaming_writer.rb
rdf-turtle-1.1.0 lib/rdf/turtle/streaming_writer.rb
rdf-turtle-1.1.0p3 lib/rdf/turtle/streaming_writer.rb
rdf-turtle-1.0.9 lib/rdf/turtle/streaming_writer.rb