Class: Exiftool
- Inherits:
-
Object
show all
- Defined in:
- lib/exiftool.rb,
lib/exiftool/parser.rb,
lib/exiftool/result.rb,
lib/exiftool/version.rb
Defined Under Namespace
Classes: ExiftoolNotInstalled, NoSuchFile, NotAFile, Parser, Result
Constant Summary
collapse
- VERSION =
Gem::Version.new('0.4.0')
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(filenames, exiftool_opts = '') ⇒ Exiftool
Returns a new instance of Exiftool.
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/exiftool.rb', line 33
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 = "#{self.class.command} #{exiftool_opts} -j -coordFormat \"%.8f\" #{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
.command ⇒ Object
14
15
16
|
# File 'lib/exiftool.rb', line 14
def self.command
@command || 'exiftool'
end
|
.command=(path_to_exiftool) ⇒ Object
10
11
12
|
# File 'lib/exiftool.rb', line 10
def self.command=(path_to_exiftool)
@command = path_to_exiftool
end
|
18
19
20
|
# File 'lib/exiftool.rb', line 18
def self.exiftool_installed?
exiftool_version > 0
end
|
This is a string, not a float, to handle versions like “9.40” properly.
23
24
25
|
# File 'lib/exiftool.rb', line 23
def self.exiftool_version
@exiftool_version ||= `#{command} -ver 2> /dev/null`.chomp
end
|
.expand_path(filename) ⇒ Object
27
28
29
30
31
|
# File 'lib/exiftool.rb', line 27
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
72
73
74
|
# File 'lib/exiftool.rb', line 72
def errors?
@file2result.values.any? { |ea| ea.errors? }
end
|
#files_with_results ⇒ Object
56
57
58
|
# File 'lib/exiftool.rb', line 56
def files_with_results
@file2result.values.collect { |r| r.source_file unless r.errors? }.compact
end
|
#result_for(filename) ⇒ Object
52
53
54
|
# File 'lib/exiftool.rb', line 52
def result_for(filename)
@file2result[self.class.expand_path(filename)]
end
|
#symbol_display_hash ⇒ Object
68
69
70
|
# File 'lib/exiftool.rb', line 68
def symbol_display_hash
first.symbol_display_hash
end
|
#to_display_hash ⇒ Object
64
65
66
|
# File 'lib/exiftool.rb', line 64
def to_display_hash
first.to_display_hash
end
|
#to_hash ⇒ Object
60
61
62
|
# File 'lib/exiftool.rb', line 60
def to_hash
first.to_hash
end
|