exiv2 0.0.4 → 0.0.5
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.
- data/Gemfile.lock +1 -1
- data/lib/exiv2.rb +2 -0
- data/lib/exiv2/exif_data.rb +3 -0
- data/lib/exiv2/iptc_data.rb +1 -20
- data/lib/exiv2/shared_methods.rb +22 -0
- data/lib/exiv2/version.rb +1 -1
- data/lib/exiv2/xmp_data.rb +1 -20
- data/spec/exiv2_spec.rb +79 -42
- metadata +6 -4
data/Gemfile.lock
CHANGED
data/lib/exiv2.rb
CHANGED
data/lib/exiv2/iptc_data.rb
CHANGED
@@ -1,22 +1,3 @@
|
|
1
1
|
class Exiv2::IptcData
|
2
|
-
|
3
|
-
result = {}
|
4
|
-
|
5
|
-
self.each do |key, value|
|
6
|
-
if result[key]
|
7
|
-
if result[key].is_a? Array
|
8
|
-
result[key] << value
|
9
|
-
else
|
10
|
-
result[key] = [result[key], value]
|
11
|
-
end
|
12
|
-
else
|
13
|
-
result[key] = value
|
14
|
-
end
|
15
|
-
end
|
16
|
-
result
|
17
|
-
end
|
18
|
-
|
19
|
-
def inspect
|
20
|
-
"#<Exiv2::IptcData: #{self.to_hash.inspect}>"
|
21
|
-
end
|
2
|
+
include SharedMethods
|
22
3
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module SharedMethods
|
2
|
+
def to_hash
|
3
|
+
result = {}
|
4
|
+
|
5
|
+
self.each do |key, value|
|
6
|
+
if result[key]
|
7
|
+
if result[key].is_a? Array
|
8
|
+
result[key] << value
|
9
|
+
else
|
10
|
+
result[key] = [result[key], value]
|
11
|
+
end
|
12
|
+
else
|
13
|
+
result[key] = value
|
14
|
+
end
|
15
|
+
end
|
16
|
+
result
|
17
|
+
end
|
18
|
+
|
19
|
+
def inspect
|
20
|
+
"#<#{self.class.name}: #{self.to_hash.inspect}>"
|
21
|
+
end
|
22
|
+
end
|
data/lib/exiv2/version.rb
CHANGED
data/lib/exiv2/xmp_data.rb
CHANGED
@@ -1,22 +1,3 @@
|
|
1
1
|
class Exiv2::XmpData
|
2
|
-
|
3
|
-
result = {}
|
4
|
-
|
5
|
-
self.each do |key, value|
|
6
|
-
if result[key]
|
7
|
-
if result[key].is_a? Array
|
8
|
-
result[key] << value
|
9
|
-
else
|
10
|
-
result[key] = [result[key], value]
|
11
|
-
end
|
12
|
-
else
|
13
|
-
result[key] = value
|
14
|
-
end
|
15
|
-
end
|
16
|
-
result
|
17
|
-
end
|
18
|
-
|
19
|
-
def inspect
|
20
|
-
"#<Exiv2::XmpData: #{self.to_hash.inspect}>"
|
21
|
-
end
|
2
|
+
include SharedMethods
|
22
3
|
end
|
data/spec/exiv2_spec.rb
CHANGED
@@ -2,30 +2,6 @@ require 'exiv2'
|
|
2
2
|
|
3
3
|
describe Exiv2 do
|
4
4
|
|
5
|
-
it "should read IPTC data" do
|
6
|
-
image = Exiv2::ImageFactory.open("spec/files/test.jpg")
|
7
|
-
image.read_metadata
|
8
|
-
iptc_data = image.iptc_data
|
9
|
-
iptc_data.should be_a(Exiv2::IptcData)
|
10
|
-
iptc_data.inspect.should == '#<Exiv2::IptcData: {"Iptc.Application2.Caption"=>"Rhubarb rhubarb rhubard", "Iptc.Application2.Keywords"=>["fish", "custard"]}>'
|
11
|
-
iptc_data.to_a.should == [
|
12
|
-
["Iptc.Application2.Caption", "Rhubarb rhubarb rhubard"],
|
13
|
-
["Iptc.Application2.Keywords", "fish"],
|
14
|
-
["Iptc.Application2.Keywords", "custard"]
|
15
|
-
]
|
16
|
-
end
|
17
|
-
|
18
|
-
it "should convert iptc data into a hash" do
|
19
|
-
image = Exiv2::ImageFactory.open("spec/files/test.jpg")
|
20
|
-
image.read_metadata
|
21
|
-
iptc_hash = image.iptc_data.to_hash
|
22
|
-
iptc_hash.should be_a(Hash)
|
23
|
-
iptc_hash.should == {
|
24
|
-
"Iptc.Application2.Caption" => "Rhubarb rhubarb rhubard",
|
25
|
-
"Iptc.Application2.Keywords" => ["fish", "custard"]
|
26
|
-
}
|
27
|
-
end
|
28
|
-
|
29
5
|
it "should handle a Pathname being passed to open" do
|
30
6
|
image = Exiv2::ImageFactory.open(Pathname.new("spec/files/test.jpg"))
|
31
7
|
image.read_metadata
|
@@ -37,30 +13,91 @@ describe Exiv2 do
|
|
37
13
|
Exiv2::ImageFactory.open("tmp/no-such-file.jpg")
|
38
14
|
}.should raise_error(Exiv2::BasicError)
|
39
15
|
end
|
40
|
-
|
41
|
-
|
16
|
+
|
17
|
+
let(:image) do
|
42
18
|
image = Exiv2::ImageFactory.open("spec/files/test.jpg")
|
43
19
|
image.read_metadata
|
44
|
-
|
45
|
-
xmp_data.should be_a(Exiv2::XmpData)
|
46
|
-
xmp_data.inspect.should == '#<Exiv2::XmpData: {"Xmp.dc.description"=>"lang=\"x-default\" This is a description", "Xmp.dc.title"=>"lang=\"x-default\" Pickled"}>'
|
47
|
-
xmp_data.to_a.should == [
|
48
|
-
["Xmp.dc.title", "lang=\"x-default\" Pickled"],
|
49
|
-
["Xmp.dc.description", "lang=\"x-default\" This is a description"]
|
50
|
-
]
|
20
|
+
image
|
51
21
|
end
|
52
22
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
23
|
+
context "IPTC data" do
|
24
|
+
before do
|
25
|
+
@iptc_data = image.iptc_data
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should read IPTC data" do
|
29
|
+
@iptc_data.should be_a(Exiv2::IptcData)
|
30
|
+
@iptc_data.inspect.should == '#<Exiv2::IptcData: {"Iptc.Application2.Caption"=>"Rhubarb rhubarb rhubard", "Iptc.Application2.Keywords"=>["fish", "custard"]}>'
|
31
|
+
@iptc_data.to_a.should == [
|
32
|
+
["Iptc.Application2.Caption", "Rhubarb rhubarb rhubard"],
|
33
|
+
["Iptc.Application2.Keywords", "fish"],
|
34
|
+
["Iptc.Application2.Keywords", "custard"]
|
35
|
+
]
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should convert iptc data into a hash" do
|
39
|
+
iptc_hash = @iptc_data.to_hash
|
40
|
+
iptc_hash.should be_a(Hash)
|
41
|
+
iptc_hash.should == {
|
42
|
+
"Iptc.Application2.Caption" => "Rhubarb rhubarb rhubard",
|
43
|
+
"Iptc.Application2.Keywords" => ["fish", "custard"]
|
44
|
+
}
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context "XMP data" do
|
49
|
+
before do
|
50
|
+
@xmp_data = image.xmp_data
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should read XMP data" do
|
54
|
+
@xmp_data.should be_a(Exiv2::XmpData)
|
55
|
+
@xmp_data.inspect.should == '#<Exiv2::XmpData: {"Xmp.dc.description"=>"lang=\"x-default\" This is a description", "Xmp.dc.title"=>"lang=\"x-default\" Pickled"}>'
|
56
|
+
@xmp_data.to_a.should == [
|
57
|
+
["Xmp.dc.title", "lang=\"x-default\" Pickled"],
|
58
|
+
["Xmp.dc.description", "lang=\"x-default\" This is a description"]
|
59
|
+
]
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should convert xmp data into a hash" do
|
63
|
+
xmp_hash = @xmp_data.to_hash
|
64
|
+
xmp_hash.should be_a(Hash)
|
65
|
+
xmp_hash.should == {
|
66
|
+
"Xmp.dc.title" => "lang=\"x-default\" Pickled",
|
67
|
+
"Xmp.dc.description" => "lang=\"x-default\" This is a description"
|
68
|
+
}
|
69
|
+
end
|
70
|
+
|
62
71
|
end
|
63
72
|
|
73
|
+
context "EXIF data" do
|
74
|
+
before do
|
75
|
+
@exif_data = image.exif_data
|
76
|
+
end
|
64
77
|
|
78
|
+
it "should read Exif data" do
|
79
|
+
@exif_data.should be_a(Exiv2::ExifData)
|
80
|
+
@exif_data.inspect.should == "#<Exiv2::ExifData: {\"Exif.Photo.PixelXDimension\"=>\"32\", \"Exif.Photo.ExifVersion\"=>\"48 50 49 48\", \"Exif.Image.Software\"=>\"plasq skitch\", \"Exif.Photo.PixelYDimension\"=>\"32\", \"Exif.Image.ExifTag\"=>\"52\"}>"
|
81
|
+
@exif_data.to_a.should == [
|
82
|
+
["Exif.Image.Software", "plasq skitch"],
|
83
|
+
["Exif.Image.ExifTag", "52"],
|
84
|
+
["Exif.Photo.ExifVersion", "48 50 49 48"],
|
85
|
+
["Exif.Photo.PixelXDimension", "32"],
|
86
|
+
["Exif.Photo.PixelYDimension", "32"]
|
87
|
+
]
|
88
|
+
end
|
65
89
|
|
90
|
+
it "should convert xmp data into a hash" do
|
91
|
+
exif_hash = @exif_data.to_hash
|
92
|
+
exif_hash.should be_a(Hash)
|
93
|
+
exif_hash.should == {
|
94
|
+
"Exif.Photo.PixelXDimension" => "32",
|
95
|
+
"Exif.Photo.ExifVersion" => "48 50 49 48",
|
96
|
+
"Exif.Image.Software" => "plasq skitch",
|
97
|
+
"Exif.Photo.PixelYDimension" => "32",
|
98
|
+
"Exif.Image.ExifTag" => "52"
|
99
|
+
}
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
66
103
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: exiv2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 21
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 5
|
10
|
+
version: 0.0.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Pete Yandell
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-08-23 00:00:00 +10:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -66,7 +66,9 @@ files:
|
|
66
66
|
- ext/exiv2/exiv2.cpp
|
67
67
|
- ext/exiv2/extconf.rb
|
68
68
|
- lib/exiv2.rb
|
69
|
+
- lib/exiv2/exif_data.rb
|
69
70
|
- lib/exiv2/iptc_data.rb
|
71
|
+
- lib/exiv2/shared_methods.rb
|
70
72
|
- lib/exiv2/version.rb
|
71
73
|
- lib/exiv2/xmp_data.rb
|
72
74
|
- spec/exiv2_spec.rb
|