sparql-client 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -68,7 +68,7 @@ Documentation
68
68
  Dependencies
69
69
  ------------
70
70
 
71
- * [RDF.rb](http://rubygems.org/gems/rdf) (>= 0.1.5)
71
+ * [RDF.rb](http://rubygems.org/gems/rdf) (>= 0.1.7)
72
72
  * [JSON](http://rubygems.org/gems/json_pure) (>= 1.2.3)
73
73
 
74
74
  Installation
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.0.3
@@ -1,3 +1,4 @@
1
+
1
2
  module SPARQL; class Client
2
3
  ##
3
4
  # A SPARQL query builder.
@@ -222,15 +223,19 @@ module SPARQL; class Client
222
223
  when :select
223
224
  buffer << 'DISTINCT' if options[:distinct]
224
225
  buffer << 'REDUCED' if options[:reduced]
225
- buffer << (variables.empty? ? '*' : variables.values.map(&:to_s).join(' '))
226
+ buffer << (variables.empty? ? '*' : variables.values.map { |v| serialize_value(v) }.join(' '))
226
227
  when :construct
227
228
  buffer << '{'
228
- buffer += options[:template].map(&:to_s)
229
+ buffer += options[:template].map do |p|
230
+ p.to_triple.map { |v| serialize_value(v) }.join(' ') + " . "
231
+ end
229
232
  buffer << '}'
230
233
  end
231
234
 
232
235
  buffer << 'WHERE {'
233
- buffer += patterns.map(&:to_s)
236
+ buffer += patterns.map do |p|
237
+ p.to_triple.map { |v| serialize_value(v) }.join(' ') + " . "
238
+ end
234
239
  if options[:filters]
235
240
  buffer += options[:filters].map { |filter| "FILTER(#{filter})" }
236
241
  end
@@ -263,5 +268,20 @@ module SPARQL; class Client
263
268
  def inspect
264
269
  sprintf("#<%s:%#0x(%s)>", self.class.name, __id__, to_s)
265
270
  end
271
+
272
+ ##
273
+ # Serializes an RDF::Value into a format appropriate for select, construct, and where clauses
274
+ #
275
+ # @param [RDF::Value]
276
+ # @return [String]
277
+ # @private
278
+ def serialize_value(value)
279
+ # SPARQL queries are UTF-8, but support ASCII-style Unicode escapes, so
280
+ # the N-Triples serializer is fine unless it's a variable:
281
+ case
282
+ when value.variable? then "?#{value.name}"
283
+ else RDF::NTriples.serialize(value)
284
+ end
285
+ end
266
286
  end
267
287
  end; end
@@ -2,7 +2,7 @@ module SPARQL; class Client
2
2
  module VERSION
3
3
  MAJOR = 0
4
4
  MINOR = 0
5
- TINY = 2
5
+ TINY = 3
6
6
  EXTRA = nil
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY].join('.')
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 2
9
- version: 0.0.2
8
+ - 3
9
+ version: 0.0.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Arto Bendiken
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-04-12 00:00:00 +02:00
18
+ date: 2010-04-17 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -70,8 +70,8 @@ dependencies:
70
70
  segments:
71
71
  - 0
72
72
  - 1
73
- - 6
74
- version: 0.1.6
73
+ - 7
74
+ version: 0.1.7
75
75
  type: :runtime
76
76
  version_requirements: *id004
77
77
  - !ruby/object:Gem::Dependency