class Riddl::Utils::Turtle::GetQuery

Public Instance Methods

response() click to toggle source
# File lib/ruby/riddl/utils/turtle.rb, line 50
def response #{{{
  a = RDF::Smart.new(@a[0])
  if a.namespaces.size > 0
    ns = ""
    if @r[-1].start_with?(":")
      if (!(a.namespaces[nil]))
        return Riddl::Parameter::Complex.new "value","text/plain", "Error parsing namespaces"
      end
      return Riddl::Parameter::Complex.new "value","application/json", JSON::pretty_generate(a.execute("PREFIX : <" + a.namespaces[nil] + "> SELECT * WHERE { #{@r[-1]} ?p ?o}"))
    else
      if (!(a.namespaces[@r[-1].partition(":")[0]]))
        return Riddl::Parameter::Complex.new "value","text/plain", "Error parsing namespaces"
      end
      return Riddl::Parameter::Complex.new "value","application/json", JSON::pretty_generate(a.execute("PREFIX #{@r[-1].partition(":")[0]}: <" + a.namespaces[@r[-1].partition(":")[0]] + "> SELECT * WHERE { #{@r[-1]} ?p ?o}"))
    end 
  end
  Riddl::Parameter::Complex.new "list","application/json", JSON::pretty_generate(a.execute("select * where {#{@r[-1]} ?p ?o}"))
end