Skip to content
Browse files

Added examples for RDF::NTriples::{Format, Reader, Writer}.

  • Loading branch information...
1 parent 4a77f24 commit eedf73b71d686e10fa19c11c08b1c5e1b182f9c3 @bendiken bendiken committed
Showing with 45 additions and 2 deletions.
  1. +7 −0 lib/rdf/ntriples/format.rb
  2. +17 −2 lib/rdf/ntriples/reader.rb
  3. +21 −0 lib/rdf/ntriples/writer.rb
View
7 lib/rdf/ntriples/format.rb
@@ -2,6 +2,13 @@ module RDF::NTriples
##
# N-Triples format specification.
#
+ # @example Obtaining an RDF/NTriples format class
+ # RDF::Format.for(:ntriples) #=> RDF::NTriples::Format
+ # RDF::Format.for("etc/doap.nt")
+ # RDF::Format.for(:file_name => "etc/doap.nt")
+ # RDF::Format.for(:file_extension => "nt")
+ # RDF::Format.for(:content_type => "text/plain")
+ #
# @see http://www.w3.org/TR/rdf-testcases/#ntriples
class Format < RDF::Format
content_type 'text/plain', :extension => :nt
View
19 lib/rdf/ntriples/reader.rb
@@ -2,8 +2,23 @@ module RDF::NTriples
##
# N-Triples parser.
#
- # @example Reading N-Triples data
- # RDF::NTriples::Reader.open("spec/data/test.nt") do |reader|
+ # @example Obtaining an RDF/NTriples reader class
+ # RDF::Reader.for(:ntriples) #=> RDF::NTriples::Reader
+ # RDF::Reader.for("etc/doap.nt")
+ # RDF::Reader.for(:file_name => "etc/doap.nt")
+ # RDF::Reader.for(:file_extension => "nt")
+ # RDF::Reader.for(:content_type => "text/plain")
+ #
+ # @example Parsing RDF statements from an NTriples file
+ # RDF::NTriples::Reader.open("etc/doap.nt") do |reader|
+ # reader.each_statement do |statement|
+ # puts statement.inspect
+ # end
+ # end
+ #
+ # @example Parsing RDF statements from an NTriples string
+ # data = StringIO.new(File.read("etc/doap.nt"))
+ # RDF::NTriples::Reader.new(data) do |reader|
# reader.each_statement do |statement|
# puts statement.inspect
# end
View
21 lib/rdf/ntriples/writer.rb
@@ -2,6 +2,27 @@ module RDF::NTriples
##
# N-Triples serializer.
#
+ # @example Obtaining an NTriples writer class
+ # RDF::Writer.for(:ntriples) #=> RDF::NTriples::Writer
+ # RDF::Writer.for("etc/test.nt")
+ # RDF::Writer.for(:file_name => "etc/test.nt")
+ # RDF::Writer.for(:file_extension => "nt")
+ # RDF::Writer.for(:content_type => "text/plain")
+ #
+ # @example Serializing RDF statements into an NTriples file
+ # RDF::NTriples::Writer.open("etc/test.nt") do |writer|
+ # graph.each_statement do |statement|
+ # writer << statement
+ # end
+ # end
+ #
+ # @example Serializing RDF statements into an NTriples string
+ # RDF::NTriples::Writer.buffer do |writer|
+ # graph.each_statement do |statement|
+ # writer << statement
+ # end
+ # end
+ #
# @see http://www.w3.org/TR/rdf-testcases/#ntriples
class Writer < RDF::Writer
format RDF::NTriples::Format

0 comments on commit eedf73b

Please sign in to comment.
Something went wrong with that request. Please try again.