Commit 798f29f4364a42072582201cb26fb2d20b564f59

Parsing of output from reading two files work.

Commit diff

.gitignore

 
11*~
2*.swp
23pkg/*
34doc/*
toggle raw diff

data/fixtures/read_two_files.stderr

data/fixtures/read_two_files.stdout

 
1======== /home/janfri/test_photos/2008-02-16_0013.jpe
2ExifToolVersion 7.03
3FileName 2008-02-16_0013.jpe
4Directory /home/janfri/test_photos
5FileSize 2 MB
6FileModifyDate 2008:02:16 16:10:54
7FileType JPEG
8MIMEType image/jpeg
9ExifByteOrder Big-endian (Motorola)
10ImageDescription KONICA MINOLTA DIGITAL CAMERA
11Make KONICA MINOLTA
12Model DYNAX 7D
13Orientation Horizontal (normal)
14XResolution 72
15YResolution 72
16ResolutionUnit inches
17Software DYNAX 7D v1.10
18ModifyDate 2008:02:16 16:10:52
19YCbCrPositioning Centered
20ExposureTime 1/250
21FNumber 6.7
22ExposureProgram Aperture-priority AE
23ISO 100
24ExifVersion 0221
25DateTimeOriginal 2008:02:16 16:10:52
26CreateDate 2008:02:16 16:10:52
27ComponentsConfiguration YCbCr
28BrightnessValue 8.5
29ExposureCompensation 0
30MaxApertureValue 6.7
31MeteringMode Center-weighted average
32LightSource Unknown (0)
33Flash Off
34FocalLength 300.0mm
35SubjectLocation 1504 1000 256 304
36MakerNoteVersion MLT0
37MinoltaImageSize Large
38WhiteBalance Auto
39FocusMode Single-shot AF
40AFPoints Center
41ISOSetting Auto
42FreeMemoryCardImages 49
43Rotation Horizontal (normal)
44ImageNumber 6
45NoiseReduction Unknown (2)
46ImageNumber2 304
47ZoneMatchingOn Off
48CompressedImageSize 2322879
49PreviewImageStart 2372611
50PreviewImageLength 46166
51SceneMode Standard
52ColorMode Adobe RGB
53MinoltaQuality Fine
54FlashExposureComp 0
55ImageStabilization On
56ZoneMatching ISO Setting Used
57ColorTemperature 0
58LensID Tamron 18-200, 28-300 or 80-300mm F3.5-6.3
59UserComment
60FlashpixVersion 0100
61ColorSpace Uncalibrated
62ExifImageWidth 3008
63ExifImageLength 2000
64InteropIndex R98 - DCF basic file (sRGB)
65InteropVersion 0100
66CustomRendered Normal
67ExposureMode Auto
68DigitalZoomRatio 0
69FocalLengthIn35mmFormat 450mm
70SceneCaptureType Standard
71GainControl None
72Contrast Normal
73Saturation Normal
74Sharpness Normal
75Compression JPEG (old-style)
76ThumbnailOffset 40306
77ThumbnailLength 3729
78ProfileCMMType Win
79ProfileVersion 2.2.0
80ProfileClass Display Device Profile
81ColorSpaceData RGB
82ProfileConnectionSpace XYZ
83ProfileDateTime 2002:05:09 20:45:47
84ProfileFileSignature acsp
85PrimaryPlatform Microsoft Corporation
86CMMFlags Not Embedded, Independent
87DeviceManufacturer KMHD
88DeviceModel
89DeviceAttributes Reflective, Glossy, Positive, Color
90RenderingIntent Perceptual
91ConnectionSpaceIlluminant 0.96419 1 0.82487
92ProfileCreator KMHD
93ProfileID 0
94ProfileCopyright Copyright 2002 Minolta Co.,Ltd.
95ProfileDescription AdobeRGB1998 ((KONICA MINOLTA CAM
96GreenTRC (Binary data 1036 bytes, use -b option to extract)
97RedTRC (Binary data 1036 bytes, use -b option to extract)
98BlueTRC (Binary data 1036 bytes, use -b option to extract)
99RedMatrixColumn 0.6097 0.3111 0.01949
100GreenMatrixColumn 0.20529 0.62569 0.0609
101BlueMatrixColumn 0.14919 0.06319 0.7446
102MediaWhitePoint 0.95045 1 1.08905
103ImageWidth 3008
104ImageHeight 2000
105EncodingProcess Baseline DCT, Huffman coding
106BitsPerSample 8
107ColorComponents 3
108YCbCrSubSampling YCbCr4:2:2 (2 1)
109Aperture 6.7
110ImageSize 3008x2000
111PreviewImage (Binary data 46166 bytes, use -b option to extract)
112ScaleFactor35efl 1.5
113ShutterSpeed 1/250
114ThumbnailImage (Binary data 3729 bytes, use -b option to extract)
115CircleOfConfusion 0.020 mm
116FocalLength35efl 300.0mm (35mm equivalent: 450.0mm)
117HyperfocalDistance 670.61 m
118LightValue 13.5
119======== /home/janfri/test_photos/2008-03-01_0004.jpg
120ExifToolVersion 7.03
121FileName 2008-03-01_0004.jpg
122Directory /home/janfri/test_photos
123FileSize 2 MB
124FileModifyDate 2008:03:13 17:47:05
125FileType JPEG
126MIMEType image/jpeg
127ExifByteOrder Big-endian (Motorola)
128ImageDescription KONICA MINOLTA DIGITAL CAMERA
129Make KONICA MINOLTA
130Model DYNAX 7D
131Orientation Horizontal (normal)
132XResolution 72
133YResolution 72
134ResolutionUnit inches
135Software DYNAX 7D v1.10
136ModifyDate 2008:03:01 13:23:22
137YCbCrPositioning Centered
138ExposureTime 1/60
139FNumber 4.5
140ExposureProgram Program AE
141ISO 400
142ExifVersion 0221
143DateTimeOriginal 2008:03:01 13:23:22
144CreateDate 2008:03:01 13:23:22
145ComponentsConfiguration YCbCr
146BrightnessValue 3.5
147ExposureCompensation 0
148MaxApertureValue 4.5
149MeteringMode Center-weighted average
150LightSource Unknown (0)
151Flash On
152FocalLength 75.0mm
153SubjectLocation 1504 1000 256 304
154MakerNoteVersion MLT0
155MinoltaImageSize Large
156WhiteBalance Auto
157FocusMode Single-shot AF
158AFPoints Center
159ISOSetting Auto
160FreeMemoryCardImages 15
161Rotation Rotate 270 CW
162ImageNumber 6
163NoiseReduction Unknown (2)
164ImageNumber2 304
165ZoneMatchingOn Off
166CompressedImageSize 2191918
167PreviewImageStart 2241539
168PreviewImageLength 35524
169SceneMode Standard
170ColorMode Natural sRGB
171MinoltaQuality Fine
172FlashExposureComp 0
173ImageStabilization On
174ZoneMatching ISO Setting Used
175ColorTemperature 0
176LensID Tamron 18-200, 28-300 or 80-300mm F3.5-6.3
177UserComment
178FlashpixVersion 0100
179ColorSpace sRGB
180ExifImageWidth 3008
181ExifImageLength 2000
182InteropIndex R98 - DCF basic file (sRGB)
183InteropVersion 0100
184CustomRendered Normal
185ExposureMode Auto
186DigitalZoomRatio 0
187FocalLengthIn35mmFormat 112mm
188SceneCaptureType Standard
189GainControl Low gain up
190Contrast Normal
191Saturation Normal
192Sharpness Normal
193Compression JPEG (old-style)
194ThumbnailOffset 40306
195ThumbnailLength 3420
196ImageWidth 3008
197ImageHeight 2000
198EncodingProcess Baseline DCT, Huffman coding
199BitsPerSample 8
200ColorComponents 3
201YCbCrSubSampling YCbCr4:2:2 (2 1)
202Aperture 4.5
203ImageSize 3008x2000
204PreviewImage (Binary data 35524 bytes, use -b option to extract)
205ScaleFactor35efl 1.5
206ShutterSpeed 1/60
207ThumbnailImage (Binary data 3420 bytes, use -b option to extract)
208CircleOfConfusion 0.020 mm
209FocalLength35efl 75.0mm (35mm equivalent: 112.0mm)
210HyperfocalDistance 62.13 m
211LightValue 8.2
212 2 image files read
toggle raw diff

lib/multi_exiftool/parser.rb

 
22
33 module Parser
44
5 # :stopdoc:
56 REGEXP_TAGLINE = /^(\w+)\t(.*)$/.freeze
6 REGEXP_STRIPLINE = /^={8} /
7
7 REGEXP_STRIPLINE = /^={8} /.freeze
8 # :startdoc:
89
910 def self.parse stdout, stderr
1011 result = []
1616 when REGEXP_TAGLINE
1717 image_info[$1] = $2
1818 when REGEXP_STRIPLINE
19 result << image_info unless image_info.empty?
19 unless image_info.empty?
20 result << Result.new(image_info, {})
21 end
2022 image_info.clear
2123 end
2224 end
23 result << image_info unless image_info.empty?
25 unless image_info.empty?
26 result << Result.new(image_info, {})
27 end
2428 result
2529 end
2630
3333 attr_reader :data, :errors
3434
3535 def initialize data, errors
36 @data, @errors = data, errors
36 @data, @errors = data.clone.freeze, errors.clone.freeze
3737 end
3838
3939 end
toggle raw diff

spec/parser_spec.rb

 
44
55 describe 'parse' do
66
7 it 'should return an empty array when trying to read from a non-existing file' do
8 fix = Fixture.read_non_existing_file
9 Parser.parse(fix.stdout, fix.stderr).should == []
7 describe 'read_non_existing_file' do
8
9 it 'should return an empty array' do
10 fix = Fixture.read_non_existing_file
11 Parser.parse(fix.stdout, fix.stderr).should == []
12 end
13
1014 end
1115
12 describe 'reading one file' do
16 describe 'read_one_file' do
1317
1418 before :all do
1519 fix = Fixture.read_one_file
1620 @result = Parser.parse(fix.stdout, fix.stderr)
1721 end
1822
19 it 'should return an array with one result' do
23 it 'should return an array with one result of meaningful data' do
2024 @result.should be_kind_of(Array)
2125 @result.size.should == 1
26 data = @result.first.data
27 data['DateTimeOriginal'].should == '2005:10:06 15:41:08'
28 data['FNumber'].should == '9.0'
29 end
30
31 end
32
33 describe 'read_two_files' do
34
35 before :all do
36 fix = Fixture.read_two_files
37 @result = Parser.parse(fix.stdout, fix.stderr)
38 end
39
40 it 'should return an array with two results of meaningful data' do
41 @result.should be_kind_of(Array)
42 @result.size.should == 2
43 data1 = @result[0].data
44 data1['DateTimeOriginal'].should == '2008:02:16 16:10:52'
45 data1['FNumber'].should == '6.7'
46 data2 = @result[1].data
47 data2['DateTimeOriginal'].should == '2008:03:01 13:23:22'
48 data2['FNumber'].should == '4.5'
2249 end
2350
2451 end
toggle raw diff