Skip to content

Commit d654839

Browse files
committed
Add --extra CLI option for Vocabulary writer. Make compatibility changes to writer output.
1 parent 4a4eadb commit d654839

2 files changed

Lines changed: 12 additions & 11 deletions

File tree

lib/rdf/cli.rb

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,12 @@
88
require 'linkeddata'
99
rescue LoadError
1010
# Silently load without linkeddata, but try some others
11-
%w(reasoner rdfa rdfxml turtle).each do |ser|
11+
%w(reasoner rdfa rdfxml turtle json/ld ld/patch).each do |ser|
1212
begin
13-
require "rdf/#{ser}"
13+
require ser.include?('/') ? ser : "rdf/#{ser}"
1414
rescue LoadError
1515
end
1616
end
17-
18-
begin
19-
require 'json/ld'
20-
rescue LoadError
21-
end
2217
end
2318

2419
class OptionParser

lib/rdf/vocab/writer.rb

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ def self.options
3535
on: ["--strict"],
3636
description: "Make strict vocabulary"
3737
) {true},
38+
RDF::CLI::Option.new(
39+
symbol: :extra,
40+
datatype: String,
41+
on: ["--extra URIEncodedJSON"],
42+
description: "URI Encoded JSON representation of extra data"
43+
) {|arg| ::JSON.parse(::URI.decode(arg))},
3844
]
3945
end
4046

@@ -142,10 +148,10 @@ def from_node(name, attributes, term_type)
142148
op = term_type == :property ? "property" : "term"
143149

144150
components = [" #{op} #{name.to_sym.inspect}"]
145-
attributes.keys.sort_by(&:to_s).each do |key|
151+
attributes.keys.sort_by(&:to_s).map(&:to_sym).each do |key|
146152
next if key == :vocab
147153
value = Array(attributes[key])
148-
component = key.is_a?(Symbol) ? "#{key}: " : ":#{key.inspect} => "
154+
component = key.inspect.start_with?(':"') ? "#{key.inspect} => " : "#{key.to_s}: "
149155
value = value.first if value.length == 1
150156
component << if value.is_a?(Array)
151157
'[' + value.map {|v| serialize_value(v, key)}.sort.join(", ") + "]"
@@ -158,8 +164,8 @@ def from_node(name, attributes, term_type)
158164
end
159165

160166
def serialize_value(value, key)
161-
case key
162-
when :comment, String
167+
case key.to_s
168+
when "comment", /:/
163169
"%(#{value.gsub('(', '\(').gsub(')', '\)')}).freeze"
164170
else
165171
"#{value.inspect}.freeze"

0 commit comments

Comments
 (0)