lib/rdf/writer.rb in rdf-0.3.3 vs lib/rdf/writer.rb in rdf-0.3.4
- old
+ new
@@ -75,11 +75,11 @@
# @option options [String, #to_s] :content_type (nil)
# @return [Class]
#
# @return [Class]
def self.for(options = {})
- if format = Format.for(options)
+ if format = self.format || Format.for(options)
format.writer
end
end
##
@@ -105,11 +105,11 @@
# @param [RDF::Enumerable, #each] data
# the graph or repository to dump
# @param [IO, File] io
# the output stream or file to write to
# @param [Hash{Symbol => Object}] options
- # passed to {RDF::Writer.new} or {RDF::Writer.buffer}
+ # passed to {RDF::Writer#initialize} or {RDF::Writer.buffer}
# @return [void]
def self.dump(data, io = nil, options = {})
io = File.open(io, 'w') if io.is_a?(String)
method = data.respond_to?(:each_statement) ? :each_statement : :each
if io
@@ -145,11 +145,11 @@
##
# Writes output to the given `filename`.
#
# @param [String, #to_s] filename
# @param [Hash{Symbol => Object}] options
- # any additional options (see {RDF::Writer#initialize and {RDF::Format.for}})
+ # any additional options (see {RDF::Writer#initialize} and {RDF::Format.for})
# @option options [Symbol] :format (nil)
# @return [RDF::Writer]
def self.open(filename, options = {}, &block)
File.open(filename, 'wb') do |file|
format_options = options.dup
@@ -157,10 +157,27 @@
self.for(options[:format] || format_options).new(file, options, &block)
end
end
##
+ # Returns a symbol appropriate to use with RDF::Writer.for()
+ # @return [Symbol]
+ def self.to_sym
+ elements = self.to_s.split("::")
+ sym = elements.pop
+ sym = elements.pop if sym == 'Writer'
+ sym.downcase.to_s.to_sym
+ end
+
+ ##
+ # Returns a symbol appropriate to use with RDF::Writer.for()
+ # @return [Symbol]
+ def to_sym
+ self.class.to_sym
+ end
+
+ ##
# Initializes the writer.
#
# @param [IO, File] output
# the output stream
# @param [Hash{Symbol => Object}] options
@@ -182,12 +199,12 @@
@nodes, @node_id = {}, 0
if block_given?
write_prologue
case block.arity
- when 0 then instance_eval(&block)
- else block.call(self)
+ when 1 then block.call(self)
+ else instance_eval(&block)
end
write_epilogue
end
end
@@ -195,9 +212,21 @@
# Any additional options for this writer.
#
# @return [Hash]
# @since 0.2.2
attr_reader :options
+
+ ##
+ # Returns the base URI used for this writer.
+ #
+ # @example
+ # reader.prefixes[:dc] #=> RDF::URI('http://purl.org/dc/terms/')
+ #
+ # @return [Hash{Symbol => RDF::URI}]
+ # @since 0.3.4
+ def base_uri
+ @options[:base_uri]
+ end
##
# Returns the URI prefixes currently defined for this writer.
#
# @example