module LambdaConvert::Utils

Utils functions

Public Class Methods

find_cmd(cmd) click to toggle source

find command path array matching given `cmd` name in $PATH

# File lib/lambda_convert/utils.rb, line 7
def self.find_cmd(cmd)
  (ENV['PATH'].split(File::PATH_SEPARATOR).map do |path|
    cmd_path = File.join(path, cmd)
    cmd_path if File.executable?(cmd_path) && !File.directory?(cmd_path)
  end).compact
end
original_convert() click to toggle source
# File lib/lambda_convert/utils.rb, line 14
def self.original_convert
  find_cmd('convert').find do |path|
    output, = Open3.capture3({ 'CONVERT_CHECK_SCRIPT' => '1' }, path)
    output.strip != 'yes'
  end
end
parse_input_path(path) click to toggle source
# File lib/lambda_convert/utils.rb, line 21
def self.parse_input_path(path)
  # convert command input path could be attached with selecting syntax,
  # let's parse it and return them in an array of
  #
  #     [filename, selecting syntax]
  #
  # ref: https://www.imagemagick.org/script/command-line-processing.php
  match = /([^\[\]]+)(\[(.+)\])?/.match(path)
  [match[1], match[3]]
end