Class: Exiftoolr

Inherits:
Object
  • Object
show all
Defined in:
lib/exiftoolr.rb,
lib/exiftoolr/result.rb,
lib/exiftoolr/version.rb

Defined Under Namespace

Classes: ExiftoolNotInstalled, NoSuchFile, NotAFile, Result

Constant Summary collapse

VERSION =
"0.0.7"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filenames, exiftool_opts = "") ⇒ Exiftoolr

Returns a new instance of Exiftoolr.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/exiftoolr.rb', line 26

def initialize(filenames, exiftool_opts = "")
  @file2result = {}
  filenames = [filenames] if filenames.is_a?(String)
  unless filenames.empty?
    escaped_filenames = filenames.collect do |f|
      Shellwords.escape(self.class.expand_path(f.to_s))
    end.join(" ")
    cmd = "exiftool #{exiftool_opts} -j -coordFormat \"%.8f\" -dateFormat \"%Y-%m-%d %H:%M:%S\" #{escaped_filenames} 2> /dev/null"
    json = `#{cmd}`
    raise ExiftoolNotInstalled if json == ""
    JSON.parse(json).each do |raw|
      result = Result.new(raw)
      @file2result[result.source_file] = result
    end
  end
end

Class Method Details

.exiftool_installed?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/exiftoolr.rb', line 12

def self.exiftool_installed?
  exiftool_version > 0
end

.exiftool_versionObject



16
17
18
# File 'lib/exiftoolr.rb', line 16

def self.exiftool_version
  @@exiftool_version ||= `exiftool -ver 2> /dev/null`.to_f
end

.expand_path(filename) ⇒ Object

Raises:



20
21
22
23
24
# File 'lib/exiftoolr.rb', line 20

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

Returns:

  • (Boolean)


63
64
65
# File 'lib/exiftoolr.rb', line 63

def errors?
  @file2result.values.any? { |ea| ea.errors? }
end

#files_with_resultsObject



47
48
49
# File 'lib/exiftoolr.rb', line 47

def files_with_results
  @file2result.values.collect { |r| r.source_file unless r.errors? }.compact
end

#result_for(filename) ⇒ Object



43
44
45
# File 'lib/exiftoolr.rb', line 43

def result_for(filename)
  @file2result[self.class.expand_path(filename)]
end

#symbol_display_hashObject



59
60
61
# File 'lib/exiftoolr.rb', line 59

def symbol_display_hash
  first.symbol_display_hash
end

#to_display_hashObject



55
56
57
# File 'lib/exiftoolr.rb', line 55

def to_display_hash
  first.to_display_hash
end

#to_hashObject



51
52
53
# File 'lib/exiftoolr.rb', line 51

def to_hash
  first.to_hash
end