class MultiExiftool::Writer

Handle writing of metadata via exiftool. Composing the command for the command-line executing it and parsing possible errors.

Attributes

overwrite_original[RW]
values[RW]

Public Class Methods

mandatory_args() click to toggle source
# File lib/multi_exiftool/writer.rb, line 22
def self.mandatory_args
  if MultiExiftool.exiftool_version >= 9.79
    %w(-charset FileName=utf8 -charset utf8)
  else
    %w(-charset utf8)
  end
end
new(filenames=[], values={}) click to toggle source
Calls superclass method MultiExiftool::Executable::new
# File lib/multi_exiftool/writer.rb, line 17
def initialize filenames=[], values={}, opts={}
  super(filenames, opts)
  @values = values
end

Public Instance Methods

exiftool_args() click to toggle source

Getting the command-line arguments which would be executed when calling write. It could be useful for logging, debugging or maybe even for creating a batch-file with exiftool command to be processed.

# File lib/multi_exiftool/writer.rb, line 41
def exiftool_args
  fail MultiExiftool::Error, 'No filenames.' if filenames.empty?
  cmd = []
  cmd << Writer.mandatory_args
  cmd << options_args
  cmd << values_args
  cmd << filenames
  cmd.flatten
end
options() click to toggle source

Options to use with the exiftool command.

Calls superclass method
# File lib/multi_exiftool/writer.rb, line 31
def options
  opts = super
  opts[:overwrite_original] = true if @overwrite_original
  opts
end

Private Instance Methods

parse_results() click to toggle source
# File lib/multi_exiftool/writer.rb, line 74
def parse_results
  @errors = @stderr.read.split(/\n/)
  @errors.empty?
end
values_args() click to toggle source
# File lib/multi_exiftool/writer.rb, line 55
def values_args
  raise MultiExiftool::Error.new('No values.') if values.empty?
  values_to_param_array(@values).map {|arg| "-#{arg}"}
end
values_to_param_array(hash) click to toggle source
# File lib/multi_exiftool/writer.rb, line 60
def values_to_param_array hash
  res = []
  hash.each do |tag, val|
    if val.respond_to? :to_hash
      res << values_to_param_array(val.to_hash).map {|arg| "#{tag}:#{arg}"}
    elsif val.respond_to? :to_ary
      res << val.map {|v| "#{tag}=#{v}"}
    else
      res << "#{tag}=#{val}"
    end
  end
  res.flatten
end