lib/sparql/results.rb in sparql-0.1.0 vs lib/sparql/results.rb in sparql-0.1.1

- old
+ new

@@ -15,12 +15,12 @@ # @see http://www.w3.org/TR/rdf-sparql-json-res/ def to_json require 'json' unless defined?(::JSON) bindings = self.map do |solution| - variable_names.map do |n| - case s = solution[n] + variable_names.inject({}) do |memo, n| + memo.merge case s = solution[n] when RDF::URI {n => {:type => "uri", :value => s.to_s }} when RDF::Node {n => {:type => "bnode", :value => s.id }} when RDF::Literal @@ -30,12 +30,12 @@ {n => {:type => "literal", "xml:lang" => s.language.to_s, :value => s.to_s }} else {n => {:type => "literal", :value => s.to_s }} end end - end.compact - end.flatten + end + end { :head => { :vars => variable_names }, :results => { :bindings => bindings} }.to_json @@ -175,9 +175,10 @@ rescue LoadError => e require 'rdf/ntriples' end fmt = RDF::Format.for(format ? format.to_sym : {:content_type => content_type}) fmt ||= RDF::NTriples::Format + puts "fmt: #{fmt.inspect}, format: #{format.inspect}, content_type: #{content_type}" format ||= fmt.to_sym content_type ||= fmt.content_type.first results = solutions.dump(format, options) raise RDF::WriterError, "Unknown format #{fmt.inspect} for #{solutions.class}" unless results results