Class: Glossarist::CLI::ExportCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/glossarist/cli/export_command.rb

Constant Summary collapse

EXTENSIONS =
{
  "json" => "json",
  "jsonld" => "jsonld",
  "turtle" => "ttl",
  "tbx" => "tbx.xml",
  "jsonl" => "jsonl",
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(path, options) ⇒ ExportCommand

Returns a new instance of ExportCommand.



14
15
16
17
# File 'lib/glossarist/cli/export_command.rb', line 14

def initialize(path, options)
  @path = path
  @options = options
end

Instance Method Details

#runObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/glossarist/cli/export_command.rb', line 19

def run
  format = @options[:format]
  output_dir = File.expand_path(@options[:output])
  FileUtils.mkdir_p(output_dir)

  concepts = load_concepts
  name = resolve_shortname(concepts)

  case format
  when "json" then export_json(concepts, output_dir)
  when "jsonld" then export_document(concepts, name, output_dir, :jsonld)
  when "turtle" then export_document(concepts, name, output_dir, :turtle)
  when "tbx" then export_tbx(concepts, name, output_dir)
  when "jsonl" then export_jsonl(concepts, name, output_dir)
  end
rescue ArgumentError => e
  warn "Error: #{e.message}"
  exit 1
end