module MultiExiftool::Executable

Mixin for Reader and Writer.

Attributes

config[RW]
errors[R]
filenames[RW]
numerical[RW]
options[RW]

Public Class Methods

new(filenames=[], options={}) click to toggle source
# File lib/multi_exiftool/executable.rb, line 14
def initialize filenames=[], options={}
  @options = options
  @filenames = filenames
  @option_mapping = {numerical: :n}
  if val = options.delete(:config)
    @config = val
  end
end

Public Instance Methods

filenames=(value) click to toggle source
# File lib/multi_exiftool/executable.rb, line 29
def filenames= value
  @filenames = Array(value)
end

Private Instance Methods

execute_command() click to toggle source
# File lib/multi_exiftool/executable.rb, line 62
def execute_command
  args = ['-@', '-']
  if @config
    args = ['-config', @config] + args
  end
  stdin, @stdout, @stderr = Open3.popen3(exiftool_command, *args)
  exiftool_args.each do |part|
    stdin << part
    stdin << "\n"
  end
  stdin.close
end
exiftool_command() click to toggle source
# File lib/multi_exiftool/executable.rb, line 41
def exiftool_command
  MultiExiftool.exiftool_command
end
options_args() click to toggle source
# File lib/multi_exiftool/executable.rb, line 45
def options_args
  opts = options
  return [] if opts.empty?
  opts.map do |opt, val|
    arg = @option_mapping[opt] || opt
    if val == true
      "-#{arg}"
    else
      %W[-#{arg} #{val}]
    end
  end
end
parse_errors() click to toggle source
# File lib/multi_exiftool/executable.rb, line 80
def parse_errors
  @errors = @stderr.read.lines(chomp: true).select {|l| l =~ /^(Error|Warning):/}
end
parse_results() click to toggle source
# File lib/multi_exiftool/executable.rb, line 75
def parse_results
  parse_errors
  @errors.empty?
end
prepare_execution() click to toggle source
# File lib/multi_exiftool/executable.rb, line 58
def prepare_execution
  @errors = []
end