Module: RDF::Turtle::StreamingWriter

Included in:
Writer
Defined in:
lib/rdf/turtle/streaming_writer.rb

Overview

Streaming writer interface

Author:

Instance Method Summary collapse

Instance Method Details

#stream_epilogue

This method returns an undefined value.

Complete open statements



45
46
47
# File 'lib/rdf/turtle/streaming_writer.rb', line 45

def stream_epilogue
  @output.puts ' .' if @streaming_subject
end

#stream_prologue

This method returns an undefined value.

Write out declarations



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/rdf/turtle/streaming_writer.rb', line 11

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 ""
end

#stream_statement(statement)

This method returns an undefined value.

Write out a statement, retaining current subject and predicate to create more compact output



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/rdf/turtle/streaming_writer.rb', line 27

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, **options)} "
    @output.write "#{format_term(statement.predicate, **options)} "
  elsif statement.predicate != @streaming_predicate
    @streaming_predicate = statement.predicate
    @output.write ";\n#{indent(1)}#{format_term(statement.predicate, **options)} "
  else
    @output.write ",\n#{indent(2)}"
  end
  @output.write("#{format_term(statement.object, **options)}")
end