Skip to content

Commit

Permalink
Added a config property to add an additional line between each triple…
Browse files Browse the repository at this point in the history
…. This improves readability of documents with many definitions.
  • Loading branch information
pschijven committed Jan 25, 2024
1 parent 88cad0b commit 6ba5e02
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/iq_rdf/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def initialize(default_namespace_uri_prefix = nil, *args)
@document_language = options[:lang]

@nodes = []
@config = {}
end

def namespaces(namespaces)
Expand All @@ -39,6 +40,10 @@ def namespaces(namespaces)
self
end

def config(config = {})
@config = config
end

def <<(node)
return if node.nil?
raise ArgumentError, "Node must be an IqRdf::Uri and a Subject!" unless node.is_a?(IqRdf::Uri) and node.is_subject?
Expand Down Expand Up @@ -163,6 +168,9 @@ def to_turtle
pref = ";\n" + indent
end
s << ".\n"
if @config[:empty_line_between_triples]
s << "\n"
end
end
s
end
Expand Down
18 changes: 18 additions & 0 deletions test/turtle_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,24 @@ def test_blank_nodes_with_different_ns
qb:order 1;
eg:cost 2.25
].
rdf
end

def test_config
document = IqRdf::Document.new('http://www.test.de/')
document.config(empty_line_between_triples: true)

document << IqRdf::testemann.myCustomNote("This is an example", :lang => :en)
document << IqRdf::testemann.myCustomNote("Zweites Beispiel", :lang => :de)

assert_equal(<<rdf, document.to_turtle)
@prefix : <http://www.test.de/>.
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.
:testemann :myCustomNote "This is an example"@en.
:testemann :myCustomNote "Zweites Beispiel"@de.
rdf
end

Expand Down

0 comments on commit 6ba5e02

Please sign in to comment.