lib/libis/format/tool/pdf_merge.rb in libis-format-1.2.9 vs lib/libis/format/tool/pdf_merge.rb in libis-format-1.3.0

- old
+ new

@@ -1,5 +1,7 @@ +# frozen_string_literal: true + require 'os' require 'libis/tools/extend/string' require 'libis/tools/logger' require 'libis/tools/command' @@ -7,22 +9,22 @@ require 'libis/format/config' module Libis module Format module Tool - class PdfMerge include ::Libis::Tools::Logger def self.installed? - result = Libis::Tools::Command.run(Libis::Format::Config[:java_cmd], "-version") - return false unless result[:status] == 0 + result = Libis::Tools::Command.run(Libis::Format::Config[:java_cmd], '-version') + return false unless (result[:status]).zero? + File.exist?(Libis::Format::Config[:pdf_tool]) end def self.run(source, target, options = []) - self.new.run source, target, options + new.run source, target, options end def run(source, target, options = []) source = [source] unless source.is_a?(Array) @@ -30,29 +32,27 @@ # TODO: import library and execute in current VM. For now do exactly as in MRI. end timeout = Libis::Format::Config[:timeouts][:pdf_merge] result = Libis::Tools::Command.run( - Libis::Format::Config[:java_cmd], - '-cp', Libis::Format::Config[:pdf_tool], - 'MergePdf', - '--file_output', target, - *options, - *source, - timeout: timeout, - kill_after: timeout * 2 + Libis::Format::Config[:java_cmd], + '-cp', Libis::Format::Config[:pdf_tool], + 'MergePdf', + '--file_output', target, + *options, + *source, + timeout:, + kill_after: timeout * 2 ) - raise RuntimeError, "#{self.class} took too long (> #{timeout} seconds) to complete" if result[:timeout] - raise RuntimeError, "#{self.class} errors: #{result[:err].join("\n")}" unless result[:status] == 0 && result[:err].empty? + raise "#{self.class} took too long (> #{timeout} seconds) to complete" if result[:timeout] + raise "#{self.class} errors: #{result[:err].join("\n")}" unless (result[:status]).zero? && result[:err].empty? { command: result, - files: [ target ] + files: [target] } - end end - end end end