Skip to content

Commit b9df327

Browse files
committed
Finish 2.2.4
2 parents 7c61176 + bf4ecae commit b9df327

14 files changed

Lines changed: 139 additions & 34 deletions

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,10 @@ operations on RDF files using available readers and writers.
8484
* `serialize`: Parse an RDF input and re-serializing to [N-Triples][] or another available format using `--output-format` option.
8585
* `subjects`: Returns unique subjects from parsed input.
8686

87-
The `serialize` command can also be used to serialize as a vocabulary
87+
The `serialize` command can also be used to serialize as a vocabulary.
88+
89+
Different RDF gems will augment the `rdf` script with more capabilities, which may require specifying the appropriate `--input-format` option to revel.
90+
8891
## Examples
8992

9093
require 'rdf'

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.2.3
1+
2.2.4

lib/rdf/mixin/enumerable.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def validate!
122122
# @see #each_statement
123123
# @see #enum_statement
124124
def statements(**options)
125-
Array(enum_statement)
125+
enum_statement.to_a
126126
end
127127

128128
##
@@ -311,7 +311,7 @@ def subjects(unique: true)
311311
unless unique
312312
enum_statement.map(&:subject) # TODO: optimize
313313
else
314-
Array(enum_subject)
314+
enum_subject.to_a
315315
end
316316
end
317317

@@ -376,7 +376,7 @@ def predicates(unique: true)
376376
unless unique
377377
enum_statement.map(&:predicate) # TODO: optimize
378378
else
379-
Array(enum_predicate)
379+
enum_predicate.to_a
380380
end
381381
end
382382

@@ -441,7 +441,7 @@ def objects(unique: true)
441441
unless unique
442442
enum_statement.map(&:object) # TODO: optimize
443443
else
444-
Array(enum_object)
444+
enum_object.to_a
445445
end
446446
end
447447

@@ -514,7 +514,7 @@ def terms(unique: true)
514514
flatten.
515515
compact
516516
else
517-
Array(enum_term)
517+
enum_term.to_a
518518
end
519519
end
520520

@@ -759,7 +759,7 @@ def dump(*args, **options)
759759
# @overload #to_writer
760760
# Implements #to_writer for each available instance of {RDF::Writer},
761761
# based on the writer symbol.
762-
#
762+
#
763763
# @return [String]
764764
# @see {RDF::Writer.sym}
765765
def method_missing(meth, *args)
@@ -780,7 +780,7 @@ def method_missing(meth, *args)
780780
end
781781

782782
##
783-
# @note this instantiates an writer; it could probably be done more
783+
# @note this instantiates an writer; it could probably be done more
784784
# efficiently by refactoring `RDF::Reader` and/or `RDF::Format` to expose
785785
# a list of valid format symbols.
786786
def respond_to_missing?(name, include_private = false)

lib/rdf/model/literal/boolean.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module RDF; class Literal
66
# @since 0.2.1
77
class Boolean < Literal
88
DATATYPE = RDF::XSD.boolean
9-
GRAMMAR = /^(true|false|1|0)$/i.freeze
9+
GRAMMAR = /^(true|false|1|0)$/.freeze
1010
TRUES = %w(true 1).freeze
1111
FALSES = %w(false 0).freeze
1212

lib/rdf/model/literal/double.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ module RDF; class Literal
1212
# @since 0.2.1
1313
class Double < Numeric
1414
DATATYPE = RDF::XSD.double
15-
GRAMMAR = /^(?:NaN|(?:[\+\-]?(?:INF|(?:\d+(\.\d*)?(e[\+\-]?\d+)?))))$/i.freeze
15+
GRAMMAR = /^(?:NaN|\-?INF|[+\-]?(?:\d+(:?\.\d*)?|\.\d+)(?:[eE][\+\-]?\d+)?)$/.freeze
1616

1717
##
1818
# @param [String, Float, #to_f] value
@@ -21,11 +21,11 @@ def initialize(value, datatype: nil, lexical: nil, **options)
2121
@datatype = RDF::URI(datatype || self.class.const_get(:DATATYPE))
2222
@string = lexical || (value if value.is_a?(String))
2323
@object = case
24-
when value.is_a?(::String) then case value
24+
when value.is_a?(::String) then case value.upcase
2525
when '+INF' then 1/0.0
2626
when 'INF' then 1/0.0
2727
when '-INF' then -1/0.0
28-
when 'NaN' then 0/0.0
28+
when 'NAN' then 0/0.0
2929
else Float(value.sub(/\.[eE]/, '.0E')) rescue nil
3030
end
3131
when value.is_a?(::Float) then value

lib/rdf/reader.rb

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,18 +180,37 @@ class << self
180180
# @yieldreturn [void] ignored
181181
# @raise [RDF::FormatError] if no reader found for the specified format
182182
def self.open(filename, format: nil, **options, &block)
183+
# If we're the abstract reader, and we can figure out a concrete reader from format and options, use that.
184+
if self == RDF::Reader && reader = self.for(format || {file_name: filename}.merge(options))
185+
return reader.open(filename, format: format, **options, &block)
186+
end
187+
188+
# If we are a concrete reader class or format is not nil, set accept header from our content_types.
189+
unless self == RDF::Reader
190+
headers = (options[:headers] ||= {})
191+
headers['Accept'] ||= (self.format.accept_type + %w(*/*;q=0.1)).join(", ")
192+
end
193+
183194
Util::File.open_file(filename, options) do |file|
184195
format_options = options.dup
185196
format_options[:content_type] ||= file.content_type if file.respond_to?(:content_type)
186197
format_options[:file_name] ||= filename
198+
reader = if self == RDF::Reader
199+
# We are the abstract reader class, find an appropriate reader
200+
self.for(format || format_options) do
201+
# Return a sample from the input file
202+
sample = file.read(1000)
203+
file.rewind
204+
sample
205+
end
206+
else
207+
# We are a concrete reader class
208+
self
209+
end
210+
187211
options[:encoding] ||= file.encoding if file.respond_to?(:encoding)
188212
options[:filename] ||= filename
189-
reader = self.for(format || format_options) do
190-
# Return a sample from the input file
191-
sample = file.read(1000)
192-
file.rewind
193-
sample
194-
end
213+
195214
if reader
196215
reader.new(file, options, &block)
197216
else

lib/rdf/util/file.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ def self.open_file(filename_or_url, proxy: nil, headers: {}, verify_none: false,
305305
content_type = format ? format.content_type.first : 'text/plain'
306306
# Open as a file, passing any options
307307
begin
308-
url_no_frag_or_query = RDF::URI(filename_or_url)
308+
url_no_frag_or_query = RDF::URI(filename_or_url).dup
309309
url_no_frag_or_query.query = nil
310310
url_no_frag_or_query.fragment = nil
311311
options[:encoding] ||= Encoding::UTF_8

spec/mixin_enumerable_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,14 @@
7979
end
8080
end
8181

82+
context "Not using any deprecated method" do
83+
%w(subjects predicates objects statements triples quads).each do |method|
84+
it "##{method}" do
85+
expect { subject.send(method.to_sym).to_a }.not_to output.to_stderr
86+
end
87+
end
88+
end
89+
8290
context "Obtaining all unique values" do
8391
%w(subjects predicates objects).each do |method|
8492
it "##{method}" do

spec/model_literal_spec.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,8 @@ def self.literals(*selector)
353353
%w(0 false)
354354
]
355355
it_behaves_like 'RDF::Literal validation', RDF::XSD.boolean,
356-
%w(true false tRuE FaLsE 1 0),
357-
%w(foo 10) + ['true false', 'true foo']
356+
%w(true false 1 0),
357+
%w(foo 10) + ['true false', 'true foo', 'tRuE' 'FaLsE']
358358

359359
context "object values" do
360360
{
@@ -487,7 +487,10 @@ def self.literals(*selector)
487487
%w(+INF INF),
488488
%w(INF INF),
489489
%w(-INF -INF),
490+
%w(+INF INF),
490491
#%w(NaN NaN),
492+
#%w(NAN NaN),
493+
%w(InF INF),
491494
%w(3E1 3.0E1)
492495
]
493496
it_behaves_like 'RDF::Literal validation', RDF::XSD.double,
@@ -500,12 +503,9 @@ def self.literals(*selector)
500503
1.0e+1
501504
1.0e-10
502505
123.456e4
503-
+INF
504506
INF
505507
-INF
506-
Inf
507508
NaN
508-
NAN
509509
3E1
510510
),
511511
%w(foo 12.xyz 1.0ez) + ['1.1e1 foo', 'foo 1.1e1']

spec/ntriples_spec.rb

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,6 @@
88

99
describe RDF::NTriples::Format do
1010

11-
# Restrict detected formats
12-
before(:all) do
13-
@formats = RDF::Format.class_variable_get(:@@subclasses)
14-
RDF::Format.class_variable_set(:@@subclasses, [])
15-
end
16-
before(:all) {RDF::Format.class_variable_set(:@@subclasses, @formats)}
17-
1811
# @see lib/rdf/spec/format.rb in rdf-spec
1912
it_behaves_like 'an RDF::Format' do
2013
let(:format_class) { described_class }

0 commit comments

Comments
 (0)