Module: LambdaConvert::Utils

Defined in:
lib/lambda_convert/utils.rb

Overview

Utils functions

Class Method Summary collapse

Class Method Details

.find_cmd(cmd) ⇒ Object

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



5
6
7
8
9
10
# File 'lib/lambda_convert/utils.rb', line 5

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_convertObject



12
13
14
15
16
17
18
# File 'lib/lambda_convert/utils.rb', line 12

def self.original_convert
  find_cmd('convert').find do |path|
    # TODO: maybe we need a more robust way to determine whether is given
    # convert path from us or someone else
    File.dirname(path) != Gem.bindir && !path.include?('.rbenv/shims')
  end
end

.parse_input_path(path) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/lambda_convert/utils.rb', line 20

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