rdf 1.1.0.p3 → 1.1.0p4

Sign up to get free protection for your applications and to get access to all the features.
data/lib/rdf/writer.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # -*- encoding: utf-8 -*-
1
2
  module RDF
2
3
  ##
3
4
  # The base class for RDF serializers.
@@ -198,7 +199,9 @@ module RDF
198
199
  # the encoding to use on the output stream.
199
200
  # Defaults to the format associated with `content_encoding`.
200
201
  # @option options [Boolean] :canonicalize (false)
201
- # whether to canonicalize literals when serializing
202
+ # whether to canonicalize terms when serializing
203
+ # @option options [Boolean] :validate (false)
204
+ # whether to validate terms when serializing
202
205
  # @option options [Hash] :prefixes (Hash.new)
203
206
  # the prefix mappings to use (not supported by all writers)
204
207
  # @option options [#to_s] :base_uri (nil)
@@ -305,6 +308,24 @@ module RDF
305
308
  end
306
309
  end
307
310
 
311
+ ##
312
+ # Returns `true` if statements and terms should be validated.
313
+ #
314
+ # @return [Boolean] `true` or `false`
315
+ # @since 1.0.8
316
+ def validate?
317
+ @options[:validate]
318
+ end
319
+
320
+ ##
321
+ # Returns `true` if terms should be canonicalized.
322
+ #
323
+ # @return [Boolean] `true` or `false`
324
+ # @since 1.0.8
325
+ def canonicalize?
326
+ @options[:canonicalize]
327
+ end
328
+
308
329
  ##
309
330
  # Flushes the underlying output buffer.
310
331
  #
@@ -358,15 +379,21 @@ module RDF
358
379
  ##
359
380
  # @param [RDF::Statement] statement
360
381
  # @return [void] `self`
382
+ # @raise [RDF::WriterError] if validating and attempting to write an invalid {RDF::Statement} or if canonicalizing a statement which cannot be canonicalized.
361
383
  def write_statement(statement)
384
+ statement = statement.canonicalize! if canonicalize?
385
+ raise RDF::WriterError, "Statement #{statement.inspect} is invalid" if validate? && statement.invalid?
362
386
  write_triple(*statement.to_triple)
363
387
  self
388
+ rescue ArgumentError => e
389
+ raise WriterError, e.message
364
390
  end
365
391
  alias_method :insert_statement, :write_statement # support the RDF::Writable interface
366
392
 
367
393
  ##
368
394
  # @param [Array<Array(RDF::Resource, RDF::URI, RDF::Term)>] triples
369
395
  # @return [void] `self`
396
+ # @raise [RDF::WriterError] if validating and attempting to write an invalid {RDF::Term}.
370
397
  def write_triples(*triples)
371
398
  triples.each { |triple| write_triple(*triple) }
372
399
  self
@@ -378,6 +405,7 @@ module RDF
378
405
  # @param [RDF::Term] object
379
406
  # @return [void] `self`
380
407
  # @raise [NotImplementedError] unless implemented in subclass
408
+ # @raise [RDF::WriterError] if validating and attempting to write an invalid {RDF::Term}.
381
409
  # @abstract
382
410
  def write_triple(subject, predicate, object)
383
411
  raise NotImplementedError.new("#{self.class}#write_triple") # override in subclasses
@@ -444,7 +472,7 @@ module RDF
444
472
  ##
445
473
  # @return [void]
446
474
  def puts(*args)
447
- @output.puts(*args.map {|s| s.force_encoding(encoding)})
475
+ @output.puts(*args.map {|s| s.encode!(encoding)})
448
476
  end
449
477
 
450
478
  ##
data/lib/rdf.rb CHANGED
@@ -5,7 +5,6 @@ require 'bigdecimal'
5
5
  require 'date'
6
6
  require 'time'
7
7
 
8
- require 'rdf/version'
9
8
  require 'rdf/version'
10
9
 
11
10
  module RDF
@@ -136,8 +135,8 @@ module RDF
136
135
 
137
136
  ##
138
137
  # @return [URI]
139
- def self.type
140
- self[:type]
138
+ def self.value
139
+ self[:value]
141
140
  end
142
141
 
143
142
  ##
@@ -171,6 +170,31 @@ module RDF
171
170
  RDF::URI.intern("http://www.w3.org/1999/02/22-rdf-syntax-ns#")
172
171
  end
173
172
 
173
+ # RDF Vocabulary terms
174
+ %w(
175
+ Alt
176
+ Bag
177
+ first
178
+ HTML
179
+ langString
180
+ List
181
+ nil
182
+ object
183
+ predicate
184
+ Property
185
+ rest
186
+ Seq
187
+ Statement
188
+ subject
189
+ type
190
+ value
191
+ XMLLiteral
192
+ ).each do |term|
193
+ term_uri = self[term.to_sym]
194
+ define_method(term) {term_uri}
195
+ module_function term.to_sym
196
+ end
197
+
174
198
  class << self
175
199
  # For compatibility with `RDF::Vocabulary.__name__`:
176
200
  alias_method :__name__, :name
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rdf
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0.p3
4
+ version: 1.1.0p4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arto Bendiken
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-06-16 00:00:00.000000000 Z
13
+ date: 2013-10-28 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rdf-spec
@@ -46,14 +46,14 @@ dependencies:
46
46
  requirements:
47
47
  - - ! '>='
48
48
  - !ruby/object:Gem::Version
49
- version: '2.12'
49
+ version: '2.14'
50
50
  type: :development
51
51
  prerelease: false
52
52
  version_requirements: !ruby/object:Gem::Requirement
53
53
  requirements:
54
54
  - - ! '>='
55
55
  - !ruby/object:Gem::Version
56
- version: '2.12'
56
+ version: '2.14'
57
57
  - !ruby/object:Gem::Dependency
58
58
  name: yard
59
59
  requirement: !ruby/object:Gem::Requirement
@@ -148,6 +148,7 @@ files:
148
148
  - lib/rdf/vocab/rdfs.rb
149
149
  - lib/rdf/vocab/rsa.rb
150
150
  - lib/rdf/vocab/rss.rb
151
+ - lib/rdf/vocab/schema.rb
151
152
  - lib/rdf/vocab/sioc.rb
152
153
  - lib/rdf/vocab/skos.rb
153
154
  - lib/rdf/vocab/wot.rb
@@ -176,7 +177,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
176
177
  version: 1.3.1
177
178
  requirements: []
178
179
  rubyforge_project: rdf
179
- rubygems_version: 2.0.3
180
+ rubygems_version: 2.0.5
180
181
  signing_key:
181
182
  specification_version: 4
182
183
  summary: A Ruby library for working with Resource Description Framework (RDF) data.