Skip to content

Commit

Permalink
Implemented an RDF::Reader#prefixes accessor method.
Browse files Browse the repository at this point in the history
  • Loading branch information
artob committed Nov 15, 2010
1 parent dddf6c8 commit cd0c9ce
Showing 1 changed file with 34 additions and 4 deletions.
38 changes: 34 additions & 4 deletions lib/rdf/reader.rb
Expand Up @@ -2,28 +2,31 @@ module RDF
##
# The base class for RDF parsers.
#
# @example Loading an RDF reader implementation
# require 'rdf/ntriples'
#
# @example Iterating over known RDF reader classes
# RDF::Reader.each { |klass| puts klass.name }
#
# @example Obtaining an RDF reader class
# RDF::Reader.for(:ntriples) #=> RDF::NTriples::Reader
# RDF::Reader.for("spec/data/test.nt")
# RDF::Reader.for(:file_name => "spec/data/test.nt")
# 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 Instantiating an RDF reader class
# RDF::Reader.for(:ntriples).new($stdin) { |reader| ... }
#
# @example Parsing RDF statements from a file
# RDF::Reader.open("spec/data/test.nt") do |reader|
# RDF::Reader.open("etc/doap.nt") do |reader|
# reader.each_statement do |statement|
# puts statement.inspect
# end
# end
#
# @example Parsing RDF statements from a string
# data = StringIO.new(File.read("spec/data/test.nt"))
# data = StringIO.new(File.read("etc/doap.nt"))
# RDF::Reader.for(:ntriples).new(data) do |reader|
# reader.each_statement do |statement|
# puts statement.inspect
Expand Down Expand Up @@ -174,6 +177,33 @@ def initialize(input = $stdin, options = {}, &block)
# @since 0.3.0
attr_reader :options

##
# Returns the URI prefixes currently defined for this reader.
#
# @example
# reader.prefixes[:dc] #=> RDF::URI('http://purl.org/dc/terms/')
#
# @return [Hash{Symbol => RDF::URI}]
# @since 0.3.0
def prefixes
options[:prefixes] ||= {}
end

##
# Defines the given URI prefixes for this reader.
#
# @example
# reader.prefixes = {
# :dc => RDF::URI('http://purl.org/dc/terms/'),
# }
#
# @param [Hash{Symbol => RDF::URI}] prefixes
# @return [Hash{Symbol => RDF::URI}]
# @since 0.3.0
def prefixes=(prefixes)
options[:prefixes] = prefixes
end

##
# Iterates the given block for each RDF statement.
#
Expand Down

0 comments on commit cd0c9ce

Please sign in to comment.