lib/mnconvert.rb in mnconvert-1.13.0 vs lib/mnconvert.rb in mnconvert-1.13.1

- old
+ new

@@ -5,11 +5,13 @@ module InputFormat MN = :metanorma STS = :sts end - MNCONVERT_JAR_PATH = File.join(File.dirname(__FILE__), "../bin/mnconvert.jar") + MNCONVERT_JAR_NAME = "mnconvert.jar".freeze + MNCONVERT_JAR_PATH = File.join(File.dirname(__FILE__), "..", "bin", + MNCONVERT_JAR_NAME) def self.jvm_options options = ["-Xss5m", "-Xmx1024m"] if RbConfig::CONFIG["host_os"].match?(/darwin|mac os/) @@ -29,16 +31,14 @@ cmd = ["java", *jvm_options, "-jar", MNCONVERT_JAR_PATH, "-v"].join(" ") message, = Open3.capture3(cmd) message.strip end - def self.convert(input_file, output_file, input_format, opts = {}) - validate(opts, input_format) + def self.convert(input_file, opts = {}) + validate(opts) - cmd = ["java", *jvm_options, "-jar", MNCONVERT_JAR_PATH, - input_file, "--input-format", input_format, - "--output", output_file, *optional_opts(opts)].join(" ") + cmd = [*java_cmd, input_file, *optional_opts(opts)].join(" ") puts cmd if opts[:debug] output_str, error_str, status = Open3.capture3(cmd) p output_str if opts[:debug] @@ -48,20 +48,35 @@ end class << self private - def validate(opts, input_format) + OPTIONAL_OPTS = { + sts_type: "--type", + imagesdir: "--imagesdir", + check_type: "--check-type", + input_format: "--input-format", + output_format: "--output-format", + output_file: "--output", + xsl_file: "--xsl-file", + }.freeze + + def java_cmd + ["java", *jvm_options, "-jar", MNCONVERT_JAR_PATH] + end + + def validate(opts) output_format = opts[:output_format] + debug = opts[:debug] - case input_format + case opts[:input_format] when InputFormat::MN validate_mn(opts, output_format) when InputFormat::STS validate_sts(opts, output_format) else - raise StandardError.new("Invalid input format: #{input_format}") + puts "input format will be decided by #{MNCONVERT_JAR_NAME}" if debug end end def validate_mn(opts, output_format) unless output_format.nil? || %w(iso niso).include?(output_format.to_s) @@ -82,19 +97,15 @@ raise StandardError.new("Invalid output format: #{output_format}") end end def optional_opts(opts) - result = { - sts_type: "--type", - imagesdir: "--imagesdir", - check_type: "--check-type", - output_format: "--output-format", - xsl_file: "--xsl-file", - }.reject { |k, _| opts[k].nil? }.map { |k, v| "#{v} #{opts[k]}" } + result = OPTIONAL_OPTS.reject { |k, _| opts[k].nil? } + result = result.map { |k, v| "#{v} #{opts[k]}" } result << "--debug" if opts[:debug] result << "--split-bibdata" if opts[:split_bibdata] + result << "--semantic" if opts[:semantic] result end end end