lib/rdf/json/reader.rb in rdf-json-0.3.0.pre vs lib/rdf/json/reader.rb in rdf-json-0.3.0
- old
+ new
@@ -40,12 +40,14 @@
##
# Initializes the RDF/JSON reader instance.
#
# @param [IO, File, String] input
# @param [Hash{Symbol => Object}] options
- # @yield [reader]
- # @yieldparam [Reader] reader
+ # any additional options (see `RDF::Reader#initialize`)
+ # @yield [reader] `self`
+ # @yieldparam [RDF::Reader] reader
+ # @yieldreturn [void] ignored
def initialize(input = $stdin, options = {}, &block)
super do
@graph = RDF::Graph.new
::JSON.parse(@input.read).each do |subject, predicates|
@@ -57,11 +59,16 @@
@graph << [subject, predicate, object]
end
end
end
- block.call(self) if block_given?
+ if block_given?
+ case block.arity
+ when 0 then instance_eval(&block)
+ else block.call(self)
+ end
+ end
end
end
##
# Parses an RDF/JSON subject string into a URI reference or blank node.
@@ -115,10 +122,11 @@
##
# Parses an RDF/JSON blank node string into an `RDF::Node` instance.
#
# @param [String] string
# @return [RDF::Node]
+ # @since 0.3.0
def parse_node(string)
RDF::Node.new(string[2..-1]) # strips off the initial '_:'
end
alias_method :parse_bnode, :parse_node
@@ -127,9 +135,10 @@
#
# @param [String] string
# @param [Hash{Symbol => Object}] options
# @option options [Boolean] :intern (false)
# @return [RDF::URI]
+ # @since 0.3.0
def parse_uri(string, options = {})
uri = RDF::URI.send(intern = intern? && options[:intern] ? :intern : :new, string)
uri.validate! if validate?
uri.canonicalize! if canonicalize? && !intern
uri