class MultiExiftool::Reader

Handle reading of metadata via exiftool. Composing the command for the command-line executing it and parsing the results as well as possible errors.

Attributes

group[RW]
tags[RW]

Public Class Methods

mandatory_args() click to toggle source
# File lib/multi_exiftool/reader.rb, line 31
def self.mandatory_args
  if MultiExiftool.exiftool_version >= 9.79
    %w(-J -charset FileName=utf8 -charset utf8)
  else
    %w(-J -charset utf8)
  end
end
new(filenames=[], opts={}) click to toggle source
Calls superclass method MultiExiftool::Executable::new
# File lib/multi_exiftool/reader.rb, line 18
def initialize filenames=[], opts={}
  super(filenames, opts)
  if val = opts.delete(:tags)
    @tags = val
  else
    @tags = []
  end
  if val = opts.delete(:group)
    @group = val
  end
  @options = opts unless opts.empty?
end

Public Instance Methods

exiftool_args() click to toggle source

Getting the command-line arguments which would be executed when calling read. 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/reader.rb, line 52
def exiftool_args
  fail MultiExiftool::Error, 'No filenames.' if filenames.empty?
  cmd = []
  cmd << Reader.mandatory_args
  cmd << options_args
  cmd << tags_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/reader.rb, line 40
def options
  opts = super
  if @group
    opts["g#@group"] = true
  end
  opts
end
tags=(value) click to toggle source
# File lib/multi_exiftool/reader.rb, line 64
def tags= value
  @tags = Array(value)
end

Private Instance Methods

parse_results() click to toggle source
# File lib/multi_exiftool/reader.rb, line 75
def parse_results
  stdout = @stdout.read
  error_string = @stderr.read.gsub(/^ .*$/, '')
  @errors = error_string.split(/\n/)
  json = JSON.parse(stdout)
  json.map {|values| Values.new(values)}
rescue JSON::ParserError
  return []
end
tags_args() click to toggle source
# File lib/multi_exiftool/reader.rb, line 70
def tags_args
  return [] unless @tags
  @tags.map {|tag| "-#{tag}"}
end