rdf 2.1.1 → 2.2.0.pre.rc1

Sign up to get free protection for your applications and to get access to all the features.
@@ -154,7 +154,7 @@ module RDF
154
154
  # Shortcut for `rdf:type`, values are String interpreted as a {URI}.
155
155
  # @return [RDF::Vocabulary::Term]
156
156
  #
157
- # @note If the ontology URI has the vocabulary namespace URI as a prefix, it may also be defined using {#property} or {#term}
157
+ # @note If the ontology URI has the vocabulary namespace URI as a prefix, it may also be defined using `#property` or `#term`
158
158
  def ontology(*args)
159
159
  case args.length
160
160
  when 0
@@ -564,16 +564,18 @@ module RDF
564
564
  attr_accessor :attributes
565
565
 
566
566
  ##
567
- # @overload URI(uri, options = {})
567
+ # @overload URI(uri, **options)
568
568
  # @param [URI, String, #to_s] uri
569
+ # @param [Hash{Symbol,Resource => Term, #to_s}] attributes
570
+ # Attributes of this vocabulary term, used for finding `label` and `comment` and to serialize the term back to RDF
569
571
  # @param [Hash{Symbol => Object}] options
570
572
  # @option options [Boolean] :validate (false)
571
573
  # @option options [Boolean] :canonicalize (false)
572
- # @option options [Hash{Symbol,Resource => Term, #to_s}] :attributes
573
- # Attributes of this vocabulary term, used for finding `label` and `comment` and to serialize the term back to RDF
574
574
  #
575
- # @overload URI(options = {})
575
+ # @overload URI(**options)
576
576
  # @param [Hash{Symbol => Object}] options
577
+ # @param [Hash{Symbol,Resource => Term, #to_s}] attributes
578
+ # Attributes of this vocabulary term, used for finding `label` and `comment` and to serialize the term back to RDF
577
579
  # @option options options [Boolean] :validate (false)
578
580
  # @option options options [Boolean] :canonicalize (false)
579
581
  # @option options [Vocabulary] :vocab The {Vocabulary} associated with this term.
@@ -591,14 +593,10 @@ module RDF
591
593
  # @option options [String, #to_s] :path The path component.
592
594
  # @option options [String, #to_s] :query The query component.
593
595
  # @option options [String, #to_s] :fragment The fragment component.
594
- # @option options [Hash{Symbol,Resource => Term, #to_s}] :attributes
595
- # Attributes of this vocabulary term, used for finding `label` and `comment` and to serialize the term back to RDF
596
- def initialize(*args, **options)
597
- @attributes = options.fetch(:attributes)
596
+ def initialize(*args, attributes:, **options)
597
+ @attributes = attributes
598
598
  if RUBY_ENGINE == "rbx"
599
- # FIXME: Somehow, this gets messed up in Rubinius
600
- args << options
601
- super(*args)
599
+ super(*args, **options)
602
600
  else
603
601
  super
604
602
  end
data/lib/rdf/writer.rb CHANGED
@@ -79,7 +79,7 @@ module RDF
79
79
  # @param [String] filename
80
80
  # @return [Class]
81
81
  #
82
- # @overload for(options = {})
82
+ # @overload for(**options)
83
83
  # Finds an RDF writer class based on various options.
84
84
  #
85
85
  # @param [Hash{Symbol => Object}] options
@@ -154,26 +154,29 @@ module RDF
154
154
  # the graph or repository to dump
155
155
  # @param [IO, File, String] io
156
156
  # the output stream or file to write to
157
+ # @param [Encoding, String, Symbol] encoding
158
+ # the encoding to use on the output stream.
159
+ # Defaults to the format associated with `content_encoding`.
157
160
  # @param [Hash{Symbol => Object}] options
158
161
  # passed to {RDF::Writer#initialize} or {RDF::Writer.buffer}
159
162
  # @return [void]
160
- def self.dump(data, io = nil, options = {})
163
+ def self.dump(data, io = nil, encoding: nil, **options)
161
164
  if io.is_a?(String)
162
165
  io = File.open(io, 'w')
163
166
  elsif io.respond_to?(:external_encoding) && io.external_encoding
164
- options = {encoding: io.external_encoding}.merge(options)
167
+ encoding ||= io.external_encoding
165
168
  end
166
- io.set_encoding(options[:encoding]) if io.respond_to?(:set_encoding) && options[:encoding]
169
+ io.set_encoding(encoding) if io.respond_to?(:set_encoding) && encoding
167
170
  method = data.respond_to?(:each_statement) ? :each_statement : :each
168
171
  if io
169
- new(io, options) do |writer|
172
+ new(io, encoding: encoding, **options) do |writer|
170
173
  data.send(method) do |statement|
171
174
  writer << statement
172
175
  end
173
176
  writer.flush
174
177
  end
175
178
  else
176
- buffer(options) do |writer|
179
+ buffer(encoding: encoding, **options) do |writer|
177
180
  data.send(method) do |statement|
178
181
  writer << statement
179
182
  end
@@ -184,19 +187,23 @@ module RDF
184
187
  ##
185
188
  # Buffers output into a string buffer.
186
189
  #
190
+ # @param [Encoding, String, Symbol] encoding
191
+ # the encoding to use on the output stream.
192
+ # Defaults to the format associated with `content_encoding`.
193
+ # @param [Hash{Symbol => Object}] options
194
+ # passed to {RDF::Writer#initialize}
187
195
  # @yield [writer]
188
196
  # @yieldparam [RDF::Writer] writer
189
197
  # @yieldreturn [void]
190
198
  # @return [String]
191
199
  # @raise [ArgumentError] if no block is provided
192
- def self.buffer(*args, &block)
193
- options = args.last.is_a?(Hash) ? args.last : {}
194
- options[:encoding] ||= Encoding::UTF_8 if RUBY_PLATFORM == "java"
200
+ def self.buffer(*args, encoding: nil, **options, &block)
201
+ encoding ||= Encoding::UTF_8 if RUBY_PLATFORM == "java"
195
202
  raise ArgumentError, "block expected" unless block_given?
196
203
 
197
204
  StringIO.open do |buffer|
198
- buffer.set_encoding(options[:encoding]) if options[:encoding]
199
- self.new(buffer, *args) { |writer| block.call(writer) }
205
+ buffer.set_encoding(encoding) if encoding
206
+ self.new(buffer, *args, encoding: encoding, **options) { |writer| block.call(writer) }
200
207
  buffer.string
201
208
  end
202
209
  end
@@ -205,16 +212,19 @@ module RDF
205
212
  # Writes output to the given `filename`.
206
213
  #
207
214
  # @param [String, #to_s] filename
215
+ # @param [Encoding, String, Symbol] encoding
216
+ # the encoding to use on the output stream.
217
+ # Defaults to the format associated with `content_encoding`.
218
+ # @param [Symbol] format (nil)
208
219
  # @param [Hash{Symbol => Object}] options
209
220
  # any additional options (see {RDF::Writer#initialize} and {RDF::Format.for})
210
- # @option options [Symbol] :format (nil)
211
221
  # @return [RDF::Writer]
212
- def self.open(filename, options = {}, &block)
222
+ def self.open(filename, encoding: nil, format: nil, **options, &block)
213
223
  File.open(filename, 'wb') do |file|
214
- file.set_encoding(options[:encoding]) if options[:encoding]
224
+ file.set_encoding(encoding) if encoding
215
225
  format_options = options.dup
216
226
  format_options[:file_name] ||= filename
217
- self.for(options[:format] || format_options).new(file, options, &block)
227
+ self.for(format || format_options).new(file, encoding: encoding, **options, &block)
218
228
  end
219
229
  end
220
230
 
@@ -256,7 +266,7 @@ module RDF
256
266
  # @yield [writer] `self`
257
267
  # @yieldparam [RDF::Writer] writer
258
268
  # @yieldreturn [void]
259
- def initialize(output = $stdout, options = {}, &block)
269
+ def initialize(output = $stdout, **options, &block)
260
270
  @output, @options = output, options.dup
261
271
  @nodes, @node_id, @node_id_map = {}, 0, {}
262
272
 
@@ -421,7 +431,7 @@ module RDF
421
431
 
422
432
  # Make sure BNodes in statement use unique identifiers
423
433
  if statement.node?
424
- terms = statement.to_quad.map do |term|
434
+ statement.to_quad.map do |term|
425
435
  if term.is_a?(RDF::Node)
426
436
  term = term.original while term.original
427
437
  @nodes[term] ||= begin
@@ -480,7 +490,7 @@ module RDF
480
490
  # @param [RDF::Term] term
481
491
  # @return [String]
482
492
  # @since 0.3.0
483
- def format_term(term, options = {})
493
+ def format_term(term, **options)
484
494
  case term
485
495
  when String then format_literal(RDF::Literal(term, options), options)
486
496
  when RDF::List then format_list(term, options)
@@ -499,7 +509,7 @@ module RDF
499
509
  # @return [String]
500
510
  # @raise [NotImplementedError] unless implemented in subclass
501
511
  # @abstract
502
- def format_node(value, options = {})
512
+ def format_node(value, **options)
503
513
  raise NotImplementedError.new("#{self.class}#format_node") # override in subclasses
504
514
  end
505
515
 
@@ -509,7 +519,7 @@ module RDF
509
519
  # @return [String]
510
520
  # @raise [NotImplementedError] unless implemented in subclass
511
521
  # @abstract
512
- def format_uri(value, options = {})
522
+ def format_uri(value, **options)
513
523
  raise NotImplementedError.new("#{self.class}#format_uri") # override in subclasses
514
524
  end
515
525
 
@@ -519,7 +529,7 @@ module RDF
519
529
  # @return [String]
520
530
  # @raise [NotImplementedError] unless implemented in subclass
521
531
  # @abstract
522
- def format_literal(value, options = {})
532
+ def format_literal(value, **options)
523
533
  raise NotImplementedError.new("#{self.class}#format_literal") # override in subclasses
524
534
  end
525
535
 
@@ -529,7 +539,7 @@ module RDF
529
539
  # @return [String]
530
540
  # @abstract
531
541
  # @since 0.2.3
532
- def format_list(value, options = {})
542
+ def format_list(value, **options)
533
543
  format_term(value.subject, options)
534
544
  end
535
545
 
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: 2.1.1
4
+ version: 2.2.0.pre.rc1
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: 2016-12-11 00:00:00.000000000 Z
13
+ date: 2016-12-31 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: link_header
@@ -150,14 +150,14 @@ dependencies:
150
150
  requirements:
151
151
  - - "~>"
152
152
  - !ruby/object:Gem::Version
153
- version: '1.17'
153
+ version: '2.3'
154
154
  type: :development
155
155
  prerelease: false
156
156
  version_requirements: !ruby/object:Gem::Requirement
157
157
  requirements:
158
158
  - - "~>"
159
159
  - !ruby/object:Gem::Version
160
- version: '1.17'
160
+ version: '2.3'
161
161
  - !ruby/object:Gem::Dependency
162
162
  name: yard
163
163
  requirement: !ruby/object:Gem::Requirement
@@ -293,9 +293,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
293
293
  version: 2.2.2
294
294
  required_rubygems_version: !ruby/object:Gem::Requirement
295
295
  requirements:
296
- - - ">="
296
+ - - ">"
297
297
  - !ruby/object:Gem::Version
298
- version: '0'
298
+ version: 1.3.1
299
299
  requirements: []
300
300
  rubyforge_project: rdf
301
301
  rubygems_version: 2.6.8