Skip to content

Commit 9dcc68b

Browse files
committed
Finish 3.2.9
2 parents bf54bb7 + 1c26cfd commit 9dcc68b

File tree

7 files changed

+87
-16
lines changed

7 files changed

+87
-16
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.2.8
1+
3.2.9

lib/rdf/cli.rb

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
rdf/xsd
2626
shacl
2727
shex
28+
yaml_ld
2829
).each do |ser|
2930
begin
3031
require ser
@@ -177,7 +178,10 @@ def to_hash
177178
# * `parse` Boolean value to determine if input files should automatically be parsed into `repository`.
178179
# * `help` used for the CLI help output.
179180
# * `lambda` code run to execute command.
180-
# * `filter` Option values that must match for command to be used
181+
# * `filter` value is a Hash whose keys are matched against selected command options. All specified `key/value` pairs are compared against the equivalent key in the current invocation.
182+
# If an Array, option value (as a string) must match any value of the array (as a string)
183+
# If a Proc, it is passed the option value and must return `true`.
184+
# Otherwise, the option value (as a string) must equal the `value` (as a string).
181185
# * `control` Used to indicate how (if) command is displayed
182186
# * `repository` Use this repository, if set
183187
# * `options` an optional array of `RDF::CLI::Option` describing command-specific options.
@@ -505,9 +509,22 @@ def self.exec(args, output: $stdout, option_parser: nil, messages: {}, **options
505509
# Make sure any selected command isn't filtered out
506510
cmds.each do |c|
507511
COMMANDS[c.to_sym].fetch(:filter, {}).each do |opt, val|
508-
if options[opt].to_s != val.to_s
509-
usage(option_parser, banner: "Command #{c.inspect} requires #{opt}: #{val}, not #{options.fetch(opt, 'null')}")
510-
raise ArgumentError, "Incompatible command #{c} used with option #{opt}=#{options[opt]}"
512+
case val
513+
when Array
514+
unless val.map(&:to_s).include?(options[opt].to_s)
515+
usage(option_parser, banner: "Command #{c.inspect} requires #{opt} in #{val.map(&:to_s).inspect}, not #{options.fetch(opt, 'null')}")
516+
raise ArgumentError, "Incompatible command #{c} used with option #{opt}=#{options[opt]}"
517+
end
518+
when Proc
519+
unless val.call(options[opt])
520+
usage(option_parser, banner: "Command #{c.inspect} #{opt} inconsistent with #{options.fetch(opt, 'null')}")
521+
raise ArgumentError, "Incompatible command #{c} used with option #{opt}=#{options[opt]}"
522+
end
523+
else
524+
unless val.to_s == options[opt].to_s
525+
usage(option_parser, banner: "Command #{c.inspect} requires compatible value for #{opt}, not #{options.fetch(opt, 'null')}")
526+
raise ArgumentError, "Incompatible command #{c} used with option #{opt}=#{options[opt]}"
527+
end
511528
end
512529
end
513530

@@ -594,7 +611,14 @@ def self.commands(format: nil, **options)
594611
# Subset commands based on filter options
595612
cmds = COMMANDS.reject do |k, c|
596613
c.fetch(:filter, {}).any? do |opt, val|
597-
options.merge(format: format)[opt].to_s != val.to_s
614+
case val
615+
when Array
616+
!val.map(&:to_s).include?(options[opt].to_s)
617+
when Proc
618+
!val.call(options[opt])
619+
else
620+
val.to_s != options[opt].to_s
621+
end
598622
end
599623
end
600624

lib/rdf/model/literal/date.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ module RDF; class Literal
33
# A date literal.
44
#
55
# @see http://www.w3.org/TR/xmlschema11-2/#date
6+
# @see https://www.w3.org/TR/xmlschema11-2/#rf-lexicalMappings-datetime
67
# @since 0.2.1
78
class Date < Temporal
89
DATATYPE = RDF::URI("http://www.w3.org/2001/XMLSchema#date")
9-
GRAMMAR = %r(\A(-?\d{4}-\d{2}-\d{2})((?:[\+\-]\d{2}:\d{2})|UTC|GMT|Z)?\Z).freeze
10+
GRAMMAR = %r(\A(#{YEARFRAG}-#{MONTHFRAG}-#{DAYFRAG})(#{TZFRAG})?\z).freeze
1011
FORMAT = '%Y-%m-%d'.freeze
1112

1213
##

lib/rdf/model/literal/datetime.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,22 @@ module RDF; class Literal
33
# A date/time literal.
44
#
55
# @see http://www.w3.org/TR/xmlschema11-2/#dateTime
6+
# @see https://www.w3.org/TR/xmlschema11-2/#rf-lexicalMappings-datetime
67
# @since 0.2.1
78
class DateTime < Temporal
89
DATATYPE = RDF::URI("http://www.w3.org/2001/XMLSchema#dateTime")
9-
GRAMMAR = %r(\A(-?(?:\d{4}|[1-9]\d{4,})-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?)((?:[\+\-]\d{2}:\d{2})|UTC|GMT|Z)?\Z).freeze
10+
GRAMMAR = %r(\A
11+
(#{YEARFRAG}
12+
-#{MONTHFRAG}
13+
-#{DAYFRAG}
14+
T
15+
(?:
16+
(?:
17+
#{HOURFRAG}
18+
:#{MINUTEFRAG}
19+
:#{SECONDFRAG})
20+
| #{EODFRAG}))
21+
(#{TZFRAG})?\z)x.freeze
1022
FORMAT = '%Y-%m-%dT%H:%M:%S.%L'.freeze
1123

1224
##

lib/rdf/model/literal/temporal.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ class Temporal < Literal
1010
|(?:(?<si>-)?PT(?<hr>\d{1,2})H(?:(?<mi>\d{1,2})M)?)
1111
\z)x.freeze
1212

13+
YEARFRAG = %r(-?(?:(?:[1-9]\d{3,})|(?:0\d{3})))
14+
MONTHFRAG = %r((?:(?:0[1-9])|(?:1[0-2])))
15+
DAYFRAG = %r((?:(?:0[1-9])|(?:[12]\d)|(?:3[01])))
16+
HOURFRAG = %r((?:[01]\d)|(?:2[0-3]))
17+
MINUTEFRAG = %r([0-5]\d)
18+
SECONDFRAG = %r([0-5]\d(?:\.\d+)?)
19+
EODFRAG = %r(24:00:00(?:\.0+)?)
20+
TZFRAG = %r((?:[\+\-]\d{2}:\d{2})|UTC|GMT|Z)
21+
1322
##
1423
# Compares this literal to `other` for sorting purposes.
1524
#

lib/rdf/model/literal/time.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ module RDF; class Literal
88
# following time zone indicator.
99
#
1010
# @see http://www.w3.org/TR/xmlschema11-2/#time
11+
# @see https://www.w3.org/TR/xmlschema11-2/#rf-lexicalMappings-datetime
1112
# @since 0.2.1
1213
class Time < Temporal
1314
DATATYPE = RDF::URI("http://www.w3.org/2001/XMLSchema#time")
14-
GRAMMAR = %r(\A(\d{2}:\d{2}:\d{2}(?:\.\d+)?)((?:[\+\-]\d{2}:\d{2})|UTC|GMT|Z)?\Z).freeze
15+
GRAMMAR = %r(\A((?:#{HOURFRAG}:#{MINUTEFRAG}:#{SECONDFRAG})|#{EODFRAG})(#{TZFRAG})?\z).freeze
1516
FORMAT = '%H:%M:%S.%L'.freeze
1617

1718
##

spec/cli_spec.rb

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -248,13 +248,37 @@
248248
end
249249
end
250250

251-
it "complains if filtered command is attempted" do
252-
RDF::CLI.add_command(:filtered, filter: {output_format: :nquads})
253-
expect do
254-
expect do
255-
RDF::CLI.exec(["filtered"], output_format: :ntriples)
256-
end.to raise_error(ArgumentError)
257-
end.to write(%(Command "filtered" requires output_format: nquads, not ntriples)).to(:output)
251+
describe "filter" do
252+
context "complains if filtered command is attempted" do
253+
before(:each) {RDF::CLI::COMMANDS.delete(:filtered)}
254+
255+
it "single value" do
256+
RDF::CLI.add_command(:filtered, filter: {output_format: :nquads})
257+
expect do
258+
expect do
259+
RDF::CLI.exec(["filtered"], output_format: :ntriples)
260+
end.to raise_error(ArgumentError)
261+
end.to write(%(Command "filtered" requires compatible value for output_format, not ntriples)).to(:output)
262+
end
263+
264+
it "Array of values" do
265+
RDF::CLI.add_command(:filtered, filter: {output_format: %i{nquads turtle}})
266+
expect do
267+
expect do
268+
RDF::CLI.exec(["filtered"], output_format: :ntriples)
269+
end.to raise_error(ArgumentError)
270+
end.to write(%(Command "filtered" requires output_format in ["nquads", "turtle"], not ntriples)).to(:output)
271+
end
272+
273+
it "Proc" do
274+
RDF::CLI.add_command(:filtered, filter: {output_format: ->(v) {v == :nquads}})
275+
expect do
276+
expect do
277+
RDF::CLI.exec(["filtered"], output_format: :ntriples)
278+
end.to raise_error(ArgumentError)
279+
end.to write(%(Command "filtered" output_format inconsistent with ntriples)).to(:output)
280+
end
281+
end
258282
end
259283

260284
it "uses repository specified in command" do

0 commit comments

Comments
 (0)