Class: Exiftoolr
- Inherits:
-
Object
show all
- Defined in:
- lib/exiftoolr.rb,
lib/exiftoolr/result.rb,
lib/exiftoolr/version.rb
Defined Under Namespace
Classes: ExiftoolNotInstalled, NoSuchFile, NotAFile, Parser, Result
Constant Summary
collapse
- VERSION =
Gem::Version.new("0.0.8")
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
12
13
14
|
# File 'lib/exiftoolr.rb', line 12
def self.exiftool_installed?
exiftool_version > 0
end
|
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
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
63
64
65
|
# File 'lib/exiftoolr.rb', line 63
def errors?
@file2result.values.any? { |ea| ea.errors? }
end
|
#files_with_results ⇒ Object
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_hash ⇒ Object
59
60
61
|
# File 'lib/exiftoolr.rb', line 59
def symbol_display_hash
first.symbol_display_hash
end
|
#to_display_hash ⇒ Object
55
56
57
|
# File 'lib/exiftoolr.rb', line 55
def to_display_hash
first.to_display_hash
end
|
#to_hash ⇒ Object
51
52
53
|
# File 'lib/exiftoolr.rb', line 51
def to_hash
first.to_hash
end
|