Skip to content

Commit 8d19c2c

Browse files
committed
Add --ordered option to CGI to use an extended array instead of a repository to preserve order of triples.
1 parent 6df89b6 commit 8d19c2c

2 files changed

Lines changed: 18 additions & 3 deletions

File tree

lib/rdf/cli.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,12 @@ def to_hash
296296
control: :none,
297297
on: ["-o", "--output FILE"],
298298
description: "File to write output, defaults to STDOUT") {|arg| File.open(arg, "w")},
299+
RDF::CLI::Option.new(
300+
symbol: :ordered,
301+
control: :checkbox,
302+
datatype: TrueClass,
303+
on: ["--ordered"],
304+
description: "Use order preserving repository"),
299305
RDF::CLI::Option.new(
300306
symbol: :format,
301307
control: :select,
@@ -495,14 +501,16 @@ def self.exec(args, output: $stdout, option_parser: nil, messages: {}, **options
495501
options[:format] = options[:format].to_sym if options[:format]
496502
options[:output_format] = options[:output_format].to_sym if options[:output_format]
497503

498-
@repository = RDF::Repository.new
504+
@repository = options[:ordered] ?
505+
[].extend(RDF::Enumerable, RDF::Queryable) :
506+
RDF::Repository.new
499507

500508
# Parse input files if any command requires it
501509
if cmds.any? {|c| COMMANDS[c.to_sym][:parse]}
502510
start = Time.new
503511
count = 0
504512
self.parse(args, **options) do |reader|
505-
@repository << reader
513+
reader.each_statement {|st| @repository << st}
506514
end
507515
secs = Time.new - start
508516
options[:logger].info "Parsed #{repository.count} statements with #{@readers.join(', ')} in #{secs} seconds @ #{count/secs} statements/second."

spec/cli_spec.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,16 @@
7676
end
7777
end
7878

79+
describe "--ordered" do
80+
it "sets :ordered" do
81+
options = RDF::CLI.options(%w(help --ordered) << triple)
82+
expect(options.options[:ordered]).to be_truthy
83+
end
84+
end
85+
7986
describe "--evaluate" do
8087
it "sets :evaluate" do
81-
options = RDF::CLI.options(%w(helpcount --format ntriples --evaluate) << triple)
88+
options = RDF::CLI.options(%w(help count --format ntriples --evaluate) << triple)
8289
expect(options.options[:evaluate]).to eql triple
8390
end
8491
end

0 commit comments

Comments
 (0)