Sha256: 439afdb09e664c6b72dbe13908ed427742600598200d3df630ee579a02716bdf

Contents?: true

Size: 1.55 KB

Versions: 3

Compression:

Stored size: 1.55 KB

Contents

module RDF::TriG
  ##
  # Streaming writer interface
  # @author [Gregg Kellogg](http://greggkellogg.net/)
  module StreamingWriter
    ##
    # Write out a statement, retaining current
    # `subject` and `predicate` to create more compact output
    # @return [void] `self`
    def stream_statement(statement)
      if statement.context != @streaming_context
        stream_epilogue
        if statement.context
          @output.write "#{format_term(statement.context)} {"
        end
        @streaming_context, @streaming_subject, @streaming_predicate = statement.context, statement.subject, statement.predicate
        @output.write "#{format_term(statement.subject)} "
        @output.write "#{format_term(statement.predicate)} "
      elsif statement.subject != @streaming_subject
        @output.write " .\n#{indent(@streaming_subject ? 1 : 0)}"
        @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(@streaming_subject ? 2 : 1)}#{format_term(statement.predicate)} "
      else
        @output.write ",\n#{indent(@streaming_subject ? 3 : 2)}"
      end
      @output.write("#{format_term(statement.object)}")
    end

    ##
    # Complete open statements
    # @return [void] `self`
    def stream_epilogue
      @output.puts " }" if @streaming_context
    end

    private
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rdf-trig-1.1.1 lib/rdf/trig/streaming_writer.rb
rdf-trig-1.1.0 lib/rdf/trig/streaming_writer.rb
rdf-trig-1.0.3 lib/rdf/trig/streaming_writer.rb