Class: Exiftool
  
  
  
  
  
    - Inherits:
 
    - 
      Object
      
        
        show all
      
    
 
  
  
  
  
  
      - Extended by:
 
      - Forwardable
 
  
  
  
  
  
  
  
  
    - Defined in:
 
    - lib/exiftool.rb,
  lib/exiftool/result.rb,
 lib/exiftool/version.rb,
 lib/exiftool/field_parser.rb
 
  
  
 
Overview
  
Defined Under Namespace
  
    
  
    
      Classes: ExiftoolNotInstalled, FieldParser, NoDefaultResultWithMultiget, NoSuchFile, NotAFile, Result
    
  
  
    
      Constant Summary
      collapse
    
    
      
        - VERSION =
          
        
 
        Gem::Version.new('1.2.3') 
      
    
  
  Class Attribute Summary collapse
  
  
    
      Class Method Summary
      collapse
    
    
  
    
      Instance Method Summary
      collapse
    
    
  
  
  Constructor Details
  
    
  
  
    #initialize(filenames, exiftool_opts = '')  ⇒ Exiftool 
  
  
  
  
    
Returns a new instance of Exiftool.
   
 
  
    
      
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65 
     | 
    
      # File 'lib/exiftool.rb', line 47
def initialize(filenames, exiftool_opts = '')
  @file2result = {}
  filenames = [filenames] if filenames.is_a?(String) || filenames.is_a?(Pathname)
  return if filenames.empty?
  escaped_filenames = filenames.map do |f|
    Shellwords.escape(self.class.expand_path(f.to_s))
  end.join(' ')
      cmd = "#{self.class.command} #{exiftool_opts} -j -coordFormat \"%.8f\" #{escaped_filenames} 2> /dev/null"
  json = `#{cmd}`.chomp
  raise ExiftoolNotInstalled if json == ''
  JSON.parse(json).each do |raw|
    result = Result.new(raw)
    @file2result[result.source_file] = result
  end
end
     | 
  
 
  
 
  
    Class Attribute Details
    
      
      
      
  
  
    .command  ⇒ Object 
  
  
  
  
    
      
22
23
24 
     | 
    
      # File 'lib/exiftool.rb', line 22
def self.command
  @command ||= 'exiftool'
end 
     | 
  
 
    
   
  
    Class Method Details
    
      
  
  
    
      
26
27
28 
     | 
    
      # File 'lib/exiftool.rb', line 26
def self.exiftool_installed?
  exiftool_version.to_f.positive?
end 
     | 
  
 
    
      
  
  
    
This is a string, not a float, to handle versions like “9.40” properly.
   
 
  
  
    
      
31
32
33 
     | 
    
      # File 'lib/exiftool.rb', line 31
def self.exiftool_version
  @exiftool_version ||= `#{command} -ver 2> /dev/null`.chomp
end
     | 
  
 
    
      
  
  
    .expand_path(filename)  ⇒ Object 
  
  
  
  
    
      
35
36
37
38
39
40
41 
     | 
    
      # File 'lib/exiftool.rb', line 35
def self.expand_path(filename)
  raise(NoSuchFile, filename) unless File.exist?(filename)
  raise(NotAFile, filename) unless File.file?(filename)
  File.expand_path(filename)
end 
     | 
  
 
    
   
  
    Instance Method Details
    
      
  
  
    #errors?  ⇒ Boolean 
  
  
  
  
    
      
83
84
85 
     | 
    
      # File 'lib/exiftool.rb', line 83
def errors?
  @file2result.values.any?(&:errors?)
end 
     | 
  
 
    
      
  
  
    #files_with_results  ⇒ Object 
  
  
  
  
    
      
79
80
81 
     | 
    
      # File 'lib/exiftool.rb', line 79
def files_with_results
  results.map(&:source_file)
end 
     | 
  
 
    
      
  
  
    #result_for(filename)  ⇒ Object 
  
  
  
  
    
      
75
76
77 
     | 
    
      # File 'lib/exiftool.rb', line 75
def result_for(filename)
  @file2result[self.class.expand_path(filename)]
end 
     | 
  
 
    
      
  
  
    #results(include_results_with_errors: false)  ⇒ Object 
  
  
  
  
    
      
67
68
69
70
71
72
73 
     | 
    
      # File 'lib/exiftool.rb', line 67
def results(include_results_with_errors: false)
  if include_results_with_errors
    @file2result.values
  else
    @file2result.values.reject(&:errors?)
  end
end
     |