Skip to content

Commit

Permalink
Added examples for RDF::NTriples::{Format, Reader, Writer}.
Browse files Browse the repository at this point in the history
  • Loading branch information
artob committed Mar 14, 2010
1 parent 4a77f24 commit eedf73b
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
7 changes: 7 additions & 0 deletions lib/rdf/ntriples/format.rb
Expand Up @@ -2,6 +2,13 @@ module RDF::NTriples
## ##
# N-Triples format specification. # 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 # @see http://www.w3.org/TR/rdf-testcases/#ntriples
class Format < RDF::Format class Format < RDF::Format
content_type 'text/plain', :extension => :nt content_type 'text/plain', :extension => :nt
Expand Down
19 changes: 17 additions & 2 deletions lib/rdf/ntriples/reader.rb
Expand Up @@ -2,8 +2,23 @@ module RDF::NTriples
## ##
# N-Triples parser. # N-Triples parser.
# #
# @example Reading N-Triples data # @example Obtaining an RDF/NTriples reader class
# RDF::NTriples::Reader.open("spec/data/test.nt") do |reader| # 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| # reader.each_statement do |statement|
# puts statement.inspect # puts statement.inspect
# end # end
Expand Down
21 changes: 21 additions & 0 deletions lib/rdf/ntriples/writer.rb
Expand Up @@ -2,6 +2,27 @@ module RDF::NTriples
## ##
# N-Triples serializer. # 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 # @see http://www.w3.org/TR/rdf-testcases/#ntriples
class Writer < RDF::Writer class Writer < RDF::Writer
format RDF::NTriples::Format format RDF::NTriples::Format
Expand Down

0 comments on commit eedf73b

Please sign in to comment.