class Attachs::Console

Public Class Methods

convert(source_path, destination_path, options=nil) click to toggle source
# File lib/attachs/console.rb, line 17
def convert(source_path, destination_path, options=nil)
  run "gm convert '#{source_path}' #{options} '#{destination_path}'".squeeze(' ')
end
find_content_type(path) click to toggle source
# File lib/attachs/console.rb, line 5
def find_content_type(path)
  run "file -Ib '#{path}'" do |output|
    output.split(';').first
  end
end
find_dimensions(path) click to toggle source
# File lib/attachs/console.rb, line 11
def find_dimensions(path)
  run "gm identify -format %wx%h '#{path}'" do |output|
    output.split('x').map &:to_i
  end
end

Private Class Methods

run(cmd) { |output| ... } click to toggle source
# File lib/attachs/console.rb, line 23
def run(cmd)
  Rails.logger.info "Running: #{cmd}"
  stdout, stderr, status = Open3.capture3(cmd)
  if status.success?
    output = stdout.strip
    if block_given?
      yield output
    else
      output
    end
  else
    false
  end
end