Class: SPARQL::Client::Update::InsertData

Inherits:
Operation show all
Defined in:
vendor/bundler/ruby/3.3.0/bundler/gems/sparql-client-464d3f76cfd5/lib/sparql/client/update.rb

Overview

Instance Attribute Summary collapse

Attributes inherited from Operation

#options

Instance Method Summary collapse

Methods inherited from Operation

#silent

Constructor Details

#initialize(data, **options) ⇒ InsertData

Insert statements into the graph

Examples:

INSERT DATA { http://example.org/jhacker http://xmlns.com/foaf/0.1/name \"J. Random Hacker\" .}

data = RDF::Graph.new do |graph|
  graph << [RDF::URI('http://example.org/jhacker'), RDF::Vocab::FOAF.name, "J. Random Hacker"]
end
insert_data(data)

Parameters:



174
175
176
177
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sparql-client-464d3f76cfd5/lib/sparql/client/update.rb', line 174

def initialize(data, **options)
  @data = data
  super(**options)
end

Instance Attribute Details

#dataRDF::Enumerable (readonly)

Returns:



161
162
163
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sparql-client-464d3f76cfd5/lib/sparql/client/update.rb', line 161

def data
  @data
end

Instance Method Details

#expects_statements?true

InsertData always returns result set

Returns:

  • (true)


193
194
195
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sparql-client-464d3f76cfd5/lib/sparql/client/update.rb', line 193

def expects_statements?
  false
end

#graph(uri) ⇒ self

Cause data to be inserted into the graph specified by uri

Parameters:

Returns:

  • (self)


184
185
186
187
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sparql-client-464d3f76cfd5/lib/sparql/client/update.rb', line 184

def graph(uri)
  self.options[:graph] = uri
  self
end

#to_sObject



197
198
199
200
201
202
203
204
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/sparql-client-464d3f76cfd5/lib/sparql/client/update.rb', line 197

def to_s
  query_text = 'INSERT DATA {'
  query_text += ' GRAPH ' + SPARQL::Client.serialize_uri(self.options[:graph]) + ' {' if self.options[:graph]
  query_text += "\n"
  query_text += RDF::NTriples::Writer.buffer { |writer| @data.each { |d| writer << d } }
  query_text += '}' if self.options[:graph]
  query_text += "}\n"
end