multi_exiftool 0.4.3 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 770fbc9d8a918ec8e55c71edcc2f9d608a644f11
4
- data.tar.gz: 744d23ddd5976dc1434a63410ea6a202a83fe507
3
+ metadata.gz: '08cd6e1d9c6c6ee77dcfc1a92dd00772419d0148'
4
+ data.tar.gz: 0e1252f4eebe67f630e7c4e6d79b8632a8bc8e08
5
5
  SHA512:
6
- metadata.gz: f2d4d8875e05eede4367d5cde53581c2f09035495b80e7b495a3720c4be220ec5c244540cb71ebffe10e876e440b43fee6fc70af29902974bf1ee6a59a6731df
7
- data.tar.gz: 5a221b09c6087da17049204d4079335b706e2941191d879c6c3515b88e01dd1a970fdd605552dd2be1aa0302895b0514f55383fd1b6289f54f5d454865827ed4
6
+ metadata.gz: a50fefa13b79f31013369a5441416f01ca0f521302ab47c5e1f9bbf3da2872aa716bc859e22fc5ed9c8c710781f34093fd4b6d31de7364b42d155c8fe7c20eaa
7
+ data.tar.gz: add6854570c75de94fcb73aa2bdcd309cb3fbc4b424ac040ad1d518ff10e4d772e1c86a4cefbf3e753e286606c5654fc900f5d7c4cc0b46cd0d01583ba253e54
data/Changelog CHANGED
@@ -1,3 +1,8 @@
1
+ 0.5.0
2
+ New methods Values#to_h and #to_hash.
3
+ Values#tags gives now an array instead of a set.
4
+ Tag names are not longer saved per Values instance.
5
+
1
6
  0.4.3
2
7
  Handle timestamps with additional DST string.
3
8
  Some improvements in documentation.
data/Rakefile CHANGED
@@ -5,7 +5,7 @@ require 'regtest/task'
5
5
 
6
6
  Rim.setup do |p|
7
7
  p.name = 'multi_exiftool'
8
- p.version = '0.4.3'
8
+ p.version = '0.5.0'
9
9
  p.authors = 'Jan Friedrich'
10
10
  p.email = 'janfri26@gmail.com'
11
11
  p.summary = 'This library is a wrapper for the ExifTool command-line application (http://www.sno.phy.queensu.ca/~phil/exiftool).'
@@ -9,28 +9,55 @@ module MultiExiftool
9
9
  # method_missing.
10
10
  class Values
11
11
 
12
- attr_reader :tags
12
+ @tag_map = {}
13
13
 
14
14
  def initialize values
15
15
  @values = {}
16
- @tags = Set.new
17
16
  values.map do |tag,val|
18
- @tags << tag
17
+ unified_tag = Values.unify_tag(tag)
18
+ Values.tag_map[unified_tag] = tag
19
19
  val = val.kind_of?(Hash) ? Values.new(val) : val
20
- @values[Values.unify_tag(tag)] = val
20
+ @values[unified_tag] = val
21
21
  end
22
22
  end
23
23
 
24
+ # Gets the (posible converted) value for a tag
25
+ # (tag will be unified, i.e. FNumber, fnumber or f_number
26
+ # can be used for FNumber)
24
27
  def [](tag)
25
28
  parse_value(@values[Values.unify_tag(tag)])
26
29
  end
27
30
 
28
- def self.unify_tag tag
29
- tag.gsub(/[-_]/, '').downcase
31
+ # Gets the original tag names of this instance
32
+ def tags
33
+ @values.keys.map {|tag| Values.tag_map[tag]}
34
+ end
35
+
36
+ # Generate a hash representation of this instance
37
+ # with original tag names es keys and converted
38
+ # values as values
39
+ def to_h
40
+ @values.inject(Hash.new) do |h,a|
41
+ k, v = a
42
+ h[Values.tag_map[k]] = parse_value(v)
43
+ h
44
+ end
30
45
  end
31
46
 
47
+ alias to_hash to_h
48
+
32
49
  private
33
50
 
51
+ class << self
52
+
53
+ attr_reader :tag_map
54
+
55
+ def unify_tag tag
56
+ tag.gsub(/[-_]/, '').downcase
57
+ end
58
+
59
+ end
60
+
34
61
  def method_missing tag, *args, &block
35
62
  res = self[Values.unify_tag(tag.to_s)]
36
63
  if res && block_given?
Binary file
Binary file
Binary file
@@ -119,7 +119,7 @@ class TestReader < Test::Unit::TestCase
119
119
  @reader.tags = %w(fnumber)
120
120
  res = @reader.read
121
121
  assert_equal [5.6, 6.7, 8], res.map {|e| e['FNumber']}
122
- assert_equal Set.new(%w(SourceFile FNumber)), res.first.tags
122
+ assert_equal %w(SourceFile FNumber), res.first.tags
123
123
  assert_equal [], @reader.errors
124
124
  end
125
125
  end
@@ -130,7 +130,7 @@ class TestReader < Test::Unit::TestCase
130
130
  @reader.tags = :fnumber
131
131
  res = @reader.read
132
132
  assert_equal [5.6, 6.7, 8], res.map {|e| e.fnumber}
133
- assert_equal Set.new(%w(SourceFile FNumber)), res.first.tags
133
+ assert_equal %w(SourceFile FNumber), res.first.tags
134
134
  assert_equal [], @reader.errors
135
135
  end
136
136
  end
@@ -86,12 +86,21 @@ class TestValues < Test::Unit::TestCase
86
86
 
87
87
  end
88
88
 
89
- context 'tags' do
89
+ context 'tags and to_h' do
90
+
91
+ setup do
92
+ @hash = {'FNumber' => 8, 'Author' => 'janfri', 'E-MailAddress' => 'janfri26@gmail.com', 'DateTimeOriginal' => '2017:02:20 21:07:00'}
93
+ @values = MultiExiftool::Values.new(@hash)
94
+ end
90
95
 
91
96
  test 'tags preserves the original tag names' do
92
- hash = {'FNumber' => 8, 'Author' => 'janfri', 'E-MailAddress' => 'janfri26@gmail.com'}
93
- @values = MultiExiftool::Values.new(hash)
94
- assert_equal hash.keys, @values.tags.to_a
97
+ assert_equal @hash.keys, @values.tags.to_a
98
+ end
99
+
100
+ test 'to_h preserves original tag names but uses converted values' do
101
+ dto = Time.new(2017, 2, 20, 21, 7, 0)
102
+ @hash['DateTimeOriginal'] = dto
103
+ assert_equal @hash, @values.to_h
95
104
  end
96
105
 
97
106
  end
@@ -121,7 +121,11 @@ class TestWriter < Test::Unit::TestCase
121
121
  @writer.values = {comment: 'foo', bar: 'x'}
122
122
  rc = @writer.write
123
123
  assert !rc
124
- assert_equal ["Warning: Tag 'bar' does not exist", "Error: File not found - xxx"], @writer.errors
124
+ if MultiExiftool.exiftool_version >= 10.38
125
+ assert_equal ["Warning: Tag 'bar' is not defined", "Error: File not found - xxx"], @writer.errors
126
+ else
127
+ assert_equal ["Warning: Tag 'bar' is not supported", "Error: File not found - xxx"], @writer.errors
128
+ end
125
129
  end
126
130
  end
127
131
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: multi_exiftool
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Friedrich
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-30 00:00:00.000000000 Z
11
+ date: 2017-02-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rim
@@ -114,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - exiftool, version 7.65 or higher
116
116
  rubyforge_project:
117
- rubygems_version: 2.6.6
117
+ rubygems_version: 2.6.10
118
118
  signing_key:
119
119
  specification_version: 4
120
120
  summary: This library is a wrapper for the ExifTool command-line application (http://www.sno.phy.queensu.ca/~phil/exiftool).