mini_exiftool 0.5.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
data/Changelog CHANGED
@@ -1,3 +1,13 @@
1
+ Version 0.6.0
2
+ - New methods for serialization:
3
+ - MiniExiftool.from_hash
4
+ - MiniExiftool.from_yaml
5
+ - MiniExiftool#to_hash
6
+ - MiniExiftool#to_yaml
7
+ Thanks to Andrew Bennett for the initial idea of YAML-serialization
8
+ - Refactoring of tests
9
+ - Small documetation update
10
+
1
11
  Version 0.5.1
2
12
  - Warning "parenthesize argument(s) for future version" removed
3
13
  Thanks to Greg from knobby.ws
data/README CHANGED
@@ -1,7 +1,7 @@
1
1
  = MiniExiftool
2
2
 
3
3
  This library is wrapper for the Exiftool command-line application
4
- (http://www.sno.phy.queensu.ca/~phil/exiftool/) written by Phil Harvey.
4
+ (http://www.sno.phy.queensu.ca/~phil/exiftool) written by Phil Harvey.
5
5
  Read and write access is done in a clean OO manner.
6
6
 
7
7
  == Requirements
@@ -12,20 +12,28 @@ http://www.sno.phy.queensu.ca/~phil/exiftool/install.html .
12
12
 
13
13
  == Installation
14
14
 
15
- First you need Exiftool (see under Requirements above). Simply install the gem
16
- with
15
+ First you need Exiftool (see under Requirements above). Then you can simply
16
+ install the gem with
17
17
  gem install mini_exiftool
18
+ respectively (on *nix sytems)
19
+ sudo gem install mini_exiftool
18
20
 
19
- Alternative you can download the tarball and run
20
- ruby setup config
21
- ruby setup setup
22
- sudo ruby setup install
21
+ Alternative you can download the tarball or zip file and run
22
+ ruby setup.rb config
23
+ ruby setup.rb setup
24
+ sudo ruby setup.rb install
25
+
26
+ == Contribution
27
+
28
+ The code is also hostet in a git repository on Gitorious at
29
+ http://gitorious.org/projects/mini_exiftool
30
+ feel free to contribute!
23
31
 
24
32
  == Author
25
- Jan Friedrich
33
+ Jan Friedrich <janfri DOT rubyforge AT gmail DOT com>
26
34
 
27
35
  == Copyright / License
28
- Copyright (c) 2007 by Jan Friedrich
36
+ Copyright (c) 2007-2008 by Jan Friedrich
29
37
 
30
38
  Licensed under terms of the GNU LESSER GENERAL PUBLIC LICENSE, Version 2.1,
31
39
  February 1999 (see file COPYING for more details)
data/Rakefile CHANGED
@@ -11,7 +11,7 @@ PROJECT = "MiniExiftool"
11
11
  MY_NAME = "Jan Friedrich"
12
12
 
13
13
  # Your email address, used in packaging.
14
- MY_EMAIL = "miniexiftool@googlemail.com"
14
+ MY_EMAIL = "janfri.rubyforge@gmail.com"
15
15
 
16
16
  # Short summary of your project, used in packaging.
17
17
  PROJECT_SUMMARY = 'A library for nice OO access to the Exiftool command-line application written by Phil Harvey.'
@@ -40,7 +40,7 @@ EXT_SOURCES = FileList["#{EXT_DIR}/**/*.{c,h}"]
40
40
  # Eventually add other files from EXT_DIR, like "MANIFEST"
41
41
  EXT_DIST_FILES = EXT_SOURCES + EXTCONF_FILES
42
42
  #---
43
- REQUIRE_PATHS = ["lib"]
43
+ REQUIRE_PATHS = ['lib', 'test']
44
44
  REQUIRE_PATHS << EXT_DIR if HAVE_EXT
45
45
  REQUIRE_PATHS.reverse_each do |p|
46
46
  $LOAD_PATH.unshift p
@@ -27,7 +27,7 @@ class MiniExiftool
27
27
  attr_reader :filename
28
28
  attr_accessor :numerical, :composite, :errors, :timestamps
29
29
 
30
- VERSION = '0.5.1'
30
+ VERSION = '0.6.0'
31
31
 
32
32
  # +opts+ support at the moment
33
33
  # * <code>:numerical</code> for numerical values, default is +false+
@@ -39,7 +39,7 @@ class MiniExiftool
39
39
  # <b>ATTENTION:</b> Time objects are created using <code>Time.local</code>
40
40
  # therefore they use <em>your local timezone</em>, DateTime objects instead
41
41
  # are created <em>without timezone</em>!
42
- def initialize filename, opts={}
42
+ def initialize filename=nil, opts={}
43
43
  std_opts = {:numerical => false, :composite => false, :timestamps => Time}
44
44
  opts = std_opts.update opts
45
45
  @numerical = opts[:numerical]
@@ -49,14 +49,23 @@ class MiniExiftool
49
49
  @tag_names = TagHash.new
50
50
  @changed_values = TagHash.new
51
51
  @errors = TagHash.new
52
- load filename
52
+ load filename unless filename.nil?
53
+ end
54
+
55
+ def initialize_from_hash hash # :nodoc:
56
+ hash.each_pair do |tag,value|
57
+ set_value tag, value
58
+ end
59
+ set_attributes_by_heuristic
60
+ self
53
61
  end
54
62
 
55
63
  # Load the tags of filename.
56
64
  def load filename
57
- if filename.nil? || !File.exist?(filename)
65
+ unless filename && File.exist?(filename)
58
66
  raise MiniExiftool::Error.new("File '#{filename}' does not exist.")
59
- elsif File.directory?(filename)
67
+ end
68
+ if File.directory?(filename)
60
69
  raise MiniExiftool::Error.new("'#{filename}' is a directory.")
61
70
  end
62
71
  @filename = filename
@@ -149,7 +158,36 @@ class MiniExiftool
149
158
  temp_file.delete
150
159
  all_ok
151
160
  end
152
-
161
+
162
+ # Returns a hash of the original loaded values of the MiniExiftool
163
+ # instance.
164
+ def to_hash
165
+ result = {}
166
+ @values.each do |k,v|
167
+ result[@tag_names[k]] = v
168
+ end
169
+ result
170
+ end
171
+
172
+ # Returns a YAML representation of the original loaded values of the
173
+ # MiniExiftool instance.
174
+ def to_yaml
175
+ to_hash.to_yaml
176
+ end
177
+
178
+ # Create a MiniExiftool instance from a hash
179
+ def self.from_hash hash
180
+ instance = MiniExiftool.new
181
+ instance.initialize_from_hash hash
182
+ instance
183
+ end
184
+
185
+ # Create a MiniExiftool instance from YAML data created with
186
+ # MiniExiftool#to_yaml
187
+ def self.from_yaml yaml
188
+ MiniExiftool.from_hash YAML.load(yaml)
189
+ end
190
+
153
191
  # Returns the command name of the called Exiftool application.
154
192
  def self.command
155
193
  @@cmd
@@ -239,8 +277,7 @@ class MiniExiftool
239
277
  def parse_output
240
278
  @output.each_line do |line|
241
279
  tag, value = parse_line line
242
- @tag_names[tag] = tag
243
- @values[tag] = value
280
+ set_value tag, value
244
281
  end
245
282
  end
246
283
 
@@ -277,6 +314,23 @@ class MiniExiftool
277
314
  return [tag, value]
278
315
  end
279
316
 
317
+ def set_value tag, value
318
+ @tag_names[tag] = tag
319
+ @values[tag] = value
320
+ end
321
+
322
+ def set_attributes_by_heuristic
323
+ if tags.include? 'ImageSize'
324
+ self.composite = true
325
+ end
326
+ if self.file_size.kind_of? Integer
327
+ self.numerical = true
328
+ end
329
+ if self.FileModifyDate.kind_of? DateTime
330
+ self.timestamps = DateTime
331
+ end
332
+ end
333
+
280
334
  def temp_filename
281
335
  unless @temp_filename
282
336
  temp_file = Tempfile.new('mini-exiftool')
@@ -0,0 +1,13 @@
1
+ require 'mini_exiftool'
2
+ require 'test/unit'
3
+ begin
4
+ require 'turn'
5
+ rescue LoadError
6
+ begin
7
+ require 'rubygems'
8
+ require 'turn'
9
+ rescue LoadError
10
+ end
11
+ end
12
+
13
+ include Test::Unit
@@ -1,16 +1,18 @@
1
- require 'mini_exiftool'
2
- require 'test/unit'
3
- begin
4
- require 'turn'
5
- rescue LoadError
6
- end
1
+ require 'helpers_for_test'
7
2
 
8
- class TestClassMethods < Test::Unit::TestCase
3
+ class TestClassMethods < TestCase
9
4
 
10
5
  def test_new
11
- assert_raises MiniExiftool::Error do
6
+ assert_nothing_raised do
7
+ @mini_exiftool = MiniExiftool.new
8
+ end
9
+ assert_equal nil, @mini_exiftool.filename
10
+ assert_nothing_raised do
12
11
  MiniExiftool.new nil
13
12
  end
13
+ assert_raises MiniExiftool::Error do
14
+ MiniExiftool.new false
15
+ end
14
16
  assert_raises MiniExiftool::Error do
15
17
  MiniExiftool.new ''
16
18
  end
@@ -1,11 +1,6 @@
1
- require 'mini_exiftool'
2
- require 'test/unit'
3
- begin
4
- require 'turn'
5
- rescue LoadError
6
- end
1
+ require 'helpers_for_test'
7
2
 
8
- class TestComposite < Test::Unit::TestCase
3
+ class TestComposite < TestCase
9
4
 
10
5
  def setup
11
6
  @data_dir = File.dirname(__FILE__) + '/data'
@@ -0,0 +1,89 @@
1
+ require 'helpers_for_test'
2
+ require 'yaml'
3
+
4
+ class TestDumping < TestCase
5
+
6
+ def setup
7
+ @data_dir = File.dirname(__FILE__) + '/data'
8
+ @filename_test = @data_dir + '/test.jpg'
9
+ @mini_exiftool = MiniExiftool.new @filename_test
10
+ end
11
+
12
+ def test_to_hash
13
+ hash = @mini_exiftool.to_hash
14
+ assert_equal Hash, hash.class
15
+ assert_equal @mini_exiftool.tags.size, hash.size, 'Size of Hash is not correct.'
16
+ assert_not_nil hash['ExifToolVersion'], 'Original name of exiftool tag is not preserved.'
17
+ all_ok = true
18
+ diffenent_tag = ''
19
+ hash.each do |k,v|
20
+ unless @mini_exiftool[k] == v
21
+ all_ok = false
22
+ diffenent_tag = k
23
+ break
24
+ end
25
+ end
26
+ assert all_ok, "Tag #{diffenent_tag}: expected: #{@mini_exiftool[diffenent_tag]}, actual: v"
27
+ end
28
+
29
+ def test_from_hash
30
+ hash = @mini_exiftool.to_hash
31
+ mini_exiftool_new = MiniExiftool.from_hash hash
32
+ assert_equal MiniExiftool, mini_exiftool_new.class
33
+ assert_equal @mini_exiftool.tags.size, mini_exiftool_new.tags.size
34
+ all_ok = true
35
+ diffenent_tag = ''
36
+ @mini_exiftool.tags.each do |tag|
37
+ unless @mini_exiftool[tag] == mini_exiftool_new[tag]
38
+ all_ok = false
39
+ diffenent_tag = tag
40
+ break
41
+ end
42
+ end
43
+ assert all_ok, "Tag #{diffenent_tag}: expected: #{@mini_exiftool[diffenent_tag]}, actual: #{mini_exiftool_new[diffenent_tag]}"
44
+
45
+ end
46
+
47
+ def test_to_yaml
48
+ hash = @mini_exiftool.to_hash
49
+ yaml = @mini_exiftool.to_yaml
50
+ assert_equal hash, YAML.load(yaml)
51
+ end
52
+
53
+ def test_from_yaml
54
+ hash = @mini_exiftool.to_hash
55
+ yaml = hash.to_yaml
56
+ mini_exiftool_new = MiniExiftool.from_yaml(yaml)
57
+ assert_equal MiniExiftool, mini_exiftool_new.class
58
+ assert_equal hash, mini_exiftool_new.to_hash
59
+ end
60
+
61
+ def test_heuristics_for_restoring_composite
62
+ standard = @mini_exiftool.to_hash
63
+ composite = MiniExiftool.new(@filename_test, :composite => true).to_hash
64
+ assert_equal false, MiniExiftool.from_hash(standard).composite
65
+ assert_equal true, MiniExiftool.from_hash(composite).composite
66
+ assert_equal false, MiniExiftool.from_yaml(standard.to_yaml).composite
67
+ assert_equal true, MiniExiftool.from_yaml(composite.to_yaml).composite
68
+ end
69
+
70
+ def test_heuristics_for_restoring_numerical
71
+ standard = @mini_exiftool.to_hash
72
+ numerical = MiniExiftool.new(@filename_test, :numerical => true).to_hash
73
+ assert_equal false, MiniExiftool.from_hash(standard).numerical
74
+ assert_equal true, MiniExiftool.from_hash(numerical).numerical
75
+ assert_equal false, MiniExiftool.from_yaml(standard.to_yaml).numerical
76
+ assert_equal true, MiniExiftool.from_yaml(numerical.to_yaml).numerical
77
+ end
78
+
79
+ def test_heuristics_for_restoring_timestamps
80
+ standard = @mini_exiftool.to_hash
81
+ timestamps = MiniExiftool.new(@filename_test, :timestamps => DateTime).to_hash
82
+ assert_equal Time, MiniExiftool.from_hash(standard).timestamps
83
+ assert_equal DateTime, MiniExiftool.from_hash(timestamps).timestamps
84
+ # Doesn't work yet.
85
+ # assert_equal Time, MiniExiftool.from_yaml(standard.to_yaml).timestamps
86
+ # assert_equal DateTime, MiniExiftool.from_yaml(timestamps.to_yaml).timestamps
87
+ end
88
+
89
+ end
@@ -1,11 +1,6 @@
1
- require 'mini_exiftool'
2
- require 'test/unit'
3
- begin
4
- require 'turn'
5
- rescue LoadError
6
- end
1
+ require 'helpers_for_test'
7
2
 
8
- class TestRead < Test::Unit::TestCase
3
+ class TestRead < TestCase
9
4
 
10
5
  def setup
11
6
  @data_dir = File.dirname(__FILE__) + '/data'
@@ -1,11 +1,6 @@
1
- require 'mini_exiftool'
2
- require 'test/unit'
3
- begin
4
- require 'turn'
5
- rescue LoadError
6
- end
1
+ require 'helpers_for_test'
7
2
 
8
- class TestReadNumerical < Test::Unit::TestCase
3
+ class TestReadNumerical < TestCase
9
4
 
10
5
  def setup
11
6
  @data_dir = File.dirname(__FILE__) + '/data'
@@ -1,14 +1,9 @@
1
1
  require 'digest/md5'
2
- require 'mini_exiftool'
3
2
  require 'fileutils'
4
3
  require 'tempfile'
5
- require 'test/unit'
6
- begin
7
- require 'turn'
8
- rescue LoadError
9
- end
4
+ require 'helpers_for_test'
10
5
 
11
- class TestSave < Test::Unit::TestCase
6
+ class TestSave < TestCase
12
7
 
13
8
  def setup
14
9
  @temp_file = Tempfile.new('test')
@@ -1,13 +1,8 @@
1
1
  require 'fileutils'
2
- require 'mini_exiftool'
3
2
  require 'tempfile'
4
- require 'test/unit'
5
- begin
6
- require 'turn'
7
- rescue LoadError
8
- end
3
+ require 'helpers_for_test'
9
4
 
10
- class TestSpecial < Test::Unit::TestCase
5
+ class TestSpecial < TestCase
11
6
 
12
7
  CAPTION_ABSTRACT = 'Some text for caption abstract'
13
8
 
@@ -1,14 +1,9 @@
1
1
  require 'date'
2
2
  require 'fileutils'
3
- require 'mini_exiftool'
4
3
  require 'tempfile'
5
- require 'test/unit'
6
- begin
7
- require 'turn'
8
- rescue LoadError
9
- end
4
+ require 'helpers_for_test'
10
5
 
11
- class TestSpecialDates < Test::Unit::TestCase
6
+ class TestSpecialDates < TestCase
12
7
 
13
8
  def setup
14
9
  data_dir = File.dirname(__FILE__) + '/data'
@@ -1,14 +1,9 @@
1
1
  require 'digest/md5'
2
- require 'mini_exiftool'
3
2
  require 'fileutils'
4
3
  require 'tempfile'
5
- require 'test/unit'
6
- begin
7
- require 'turn'
8
- rescue LoadError
9
- end
4
+ require 'helpers_for_test'
10
5
 
11
- class TestWrite < Test::Unit::TestCase
6
+ class TestWrite < TestCase
12
7
 
13
8
  def setup
14
9
  @temp_file = Tempfile.new('test')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mini_exiftool
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Friedrich
@@ -9,12 +9,12 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-03-03 00:00:00 +01:00
12
+ date: 2008-05-16 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
16
16
  description:
17
- email: miniexiftool@googlemail.com
17
+ email: janfri.rubyforge@gmail.com
18
18
  executables: []
19
19
 
20
20
  extensions: []
@@ -31,7 +31,9 @@ files:
31
31
  - test/test_save.rb
32
32
  - test/test_composite.rb
33
33
  - test/test_read_numerical.rb
34
+ - test/helpers_for_test.rb
34
35
  - test/test_special_dates.rb
36
+ - test/test_dumping.rb
35
37
  - examples/external_photo.rb
36
38
  - examples/print_portraits.rb
37
39
  - examples/shift_time.rb
@@ -70,7 +72,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
70
72
  requirements: []
71
73
 
72
74
  rubyforge_project: miniexiftool
73
- rubygems_version: 1.0.1
75
+ rubygems_version: 1.1.0
74
76
  signing_key:
75
77
  specification_version: 2
76
78
  summary: A library for nice OO access to the Exiftool command-line application written by Phil Harvey.
@@ -83,3 +85,4 @@ test_files:
83
85
  - test/test_composite.rb
84
86
  - test/test_read_numerical.rb
85
87
  - test/test_special_dates.rb
88
+ - test/test_dumping.rb