Module: LambdaConvert::Utils
- Defined in:
- lib/lambda_convert/utils.rb
Overview
Utils functions
Class Method Summary collapse
-
.find_cmd(cmd) ⇒ Object
find command path array matching given ‘cmd` name in $PATH.
- .original_convert ⇒ Object
- .parse_input_path(path) ⇒ Object
Class Method Details
.find_cmd(cmd) ⇒ Object
find command path array matching given ‘cmd` name in $PATH
7 8 9 10 11 12 |
# 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 ⇒ Object
14 15 16 17 18 19 |
# 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) ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# 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 |