exiftoolr 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3965c4ea2139723c1b307ae602ba6d154994295f
4
+ data.tar.gz: 132c7534e8e9a96b30cdaeb318bf85b5231f530d
5
+ SHA512:
6
+ metadata.gz: 8d0400394a42eb066765d2a525bf5dcbc0b999ecd100bfdc422fbf91abb1e7cb1d28135b640135c65f3cd1cad1f5afcb4a2c72d85df0d839f57c5cd47c589da2
7
+ data.tar.gz: 9dd74f21da6de5ae17f85dd78f49e28302a05ae741df8743033088513f34fe10fef45d1de4ab20753b57f70908acc7523991acff10c2aa5dd06033265021a1da
@@ -4,6 +4,5 @@ before_install:
4
4
  - sudo apt-get update
5
5
  - sudo apt-get install libimage-exiftool-perl
6
6
  rvm:
7
- - 1.8.7
8
7
  - 1.9.3
9
- - rbx-18mode
8
+ - 2.0.0
data/README.md CHANGED
@@ -1,12 +1,14 @@
1
1
  # Ruby wrapper for ExifTool
2
2
 
3
3
  [![Build Status](https://secure.travis-ci.org/mceachen/exiftoolr.png?branch=master)](http://travis-ci.org/mceachen/exiftoolr)
4
+ [![Gem Version](https://badge.fury.io/rb/exiftoolr.png)](http://rubygems.org/gems/exiftoolr)
5
+ [![Code Climate](https://codeclimate.com/github/mceachen/exiftoolr.png)](https://codeclimate.com/github/mceachen/exiftoolr)
4
6
 
5
7
  This gem is the simplest thing that could possibly work that
6
8
  reads the output of [exiftool](http://www.sno.phy.queensu.ca/~phil/exiftool)
7
9
  and renders it into a ruby hash, with correctly typed values and symbolized keys.
8
10
 
9
- ## Want constitutes "correct"?
11
+ ## What constitutes "correct"?
10
12
 
11
13
  * GPS latitude and longitude are rendered as signed floats,
12
14
  where north and east are positive, and west and south are negative.
@@ -72,11 +74,15 @@ Exiftoolr.new("Gemfile").errors?
72
74
 
73
75
  ## Change history
74
76
 
77
+ ### 0.0.8
78
+
79
+ * Extracted methods in parsing to make the code complexity lower. FOUR DOT OH GPA
80
+
75
81
  ### 0.0.7
76
82
 
77
83
  * Added warning values for EXIF headers that are corrupt
78
84
  * Made initialize gracefully accept an empty array, or an array of Pathname instances
79
- * Added support for ruby 1.9 and exiftool v 8.15 (Ubuntu Natty)
85
+ * Added support for ruby 1.9.3 and exiftool v8.15 (Ubuntu Natty) and v8.85 (current stable version)
80
86
 
81
87
  ### 0.0.5
82
88
 
@@ -18,8 +18,8 @@ class Exiftoolr
18
18
  end
19
19
 
20
20
  def self.expand_path(filename)
21
- raise NoSuchFile, filename unless File.exist?(filename)
22
- raise NotAFile, filename unless File.file?(filename)
21
+ raise(NoSuchFile, filename) unless File.exist?(filename)
22
+ raise(NotAFile, filename) unless File.file?(filename)
23
23
  File.expand_path(filename)
24
24
  end
25
25
 
@@ -5,39 +5,16 @@ class Exiftoolr
5
5
  class Result
6
6
  attr_reader :to_hash, :to_display_hash, :symbol_display_hash
7
7
 
8
- WORD_BOUNDARY_RES = [/([A-Z\d]+)([A-Z][a-z])/, /([a-z\d])([A-Z])/]
9
- FRACTION_RE = /^(\d+)\/(\d+)$/
10
-
11
8
  def initialize(raw_hash)
12
9
  @raw_hash = raw_hash
13
- @to_hash = { }
14
- @to_display_hash = { }
15
- @symbol_display_hash = { }
16
-
17
- @raw_hash.each do |k, raw_v|
18
- display_key = WORD_BOUNDARY_RES.inject(k) { |key, regex| key.gsub(regex, '\1 \2') }
19
- sym_key = display_key.downcase.gsub(' ', '_').to_sym
20
- begin
21
- if sym_key == :gps_latitude || sym_key == :gps_longitude
22
- value, direction = raw_v.split(" ")
23
- v = value.to_f
24
- v *= -1 if direction == 'S' || direction == 'W'
25
- elsif raw_v.is_a?(String)
26
- if display_key =~ /\bdate\b/i
27
- v = Time.parse(raw_v)
28
- else
29
- scan = raw_v.scan(FRACTION_RE).first
30
- unless scan.nil?
31
- v = Rational(*scan.collect { |ea| ea.to_i })
32
- end
33
- end
34
- end
35
- rescue StandardError => e
36
- v = "Warning: Parsing '#{raw_v}' for attribute '#{k}' raised #{e.message}"
37
- end
38
- @to_hash[sym_key] = v || raw_v
39
- @to_display_hash[display_key] = v || raw_v
40
- @symbol_display_hash[sym_key] = display_key
10
+ @to_hash = {}
11
+ @to_display_hash = {}
12
+ @symbol_display_hash = {}
13
+ @raw_hash.each do |key, raw_value|
14
+ p = Parser.new(key, raw_value)
15
+ @to_hash[p.sym_key] = p.value
16
+ @to_display_hash[p.display_key] = p.value
17
+ @symbol_display_hash[p.sym_key] = p.display_key
41
18
  end
42
19
  end
43
20
 
@@ -53,4 +30,48 @@ class Exiftoolr
53
30
  self[:error] == "Unknown file type" || self[:warning] == "Unsupported file type"
54
31
  end
55
32
  end
33
+
34
+ class Parser
35
+ WORD_BOUNDARY_RES = [/([A-Z\d]+)([A-Z][a-z])/, /([a-z\d])([A-Z])/]
36
+ FRACTION_RE = /^(\d+)\/(\d+)$/
37
+
38
+ attr_reader :display_key, :sym_key, :raw_value
39
+
40
+ def initialize(key, raw_value)
41
+ @display_key = WORD_BOUNDARY_RES.inject(key) { |k, regex| k.gsub(regex, '\1 \2') }
42
+ @sym_key = display_key.downcase.gsub(' ', '_').to_sym
43
+ @raw_value = raw_value
44
+ end
45
+
46
+ def value
47
+ for_lat_long ||
48
+ for_date ||
49
+ for_fraction ||
50
+ raw_value
51
+ rescue StandardError => e
52
+ v = "Warning: Parsing '#{raw_value}' for attribute '#{k}' raised #{e.message}"
53
+ end
54
+
55
+ private
56
+
57
+ def for_lat_long
58
+ if sym_key == :gps_latitude || sym_key == :gps_longitude
59
+ value, direction = raw_value.split(" ")
60
+ value.to_f * (['S', 'W'].include?(direction) ? -1 : 1)
61
+ end
62
+ end
63
+
64
+ def for_date
65
+ if raw_value.is_a?(String) && display_key =~ /\bdate\b/i
66
+ Time.parse(raw_value)
67
+ end
68
+ end
69
+
70
+ def for_fraction
71
+ if raw_value.is_a?(String)
72
+ scan = raw_value.scan(FRACTION_RE).first
73
+ v = Rational(*scan.collect { |ea| ea.to_i }) unless scan.nil?
74
+ end
75
+ end
76
+ end
56
77
  end
@@ -1,3 +1,3 @@
1
1
  class Exiftoolr
2
- VERSION = "0.0.7"
2
+ VERSION = Gem::Version.new("0.0.8")
3
3
  end
@@ -61,7 +61,7 @@ class TestExiftoolr < Test::Unit::TestCase
61
61
  def ignorable_key? key
62
62
  @ignorable_keys ||= begin
63
63
  ignorable = [:file_modify_date, :directory, :source_file, :exif_tool_version]
64
- ignorable += [:modify_date, :create_date, :date_time_original] if Exiftoolr.exiftool_version <= 8.2
64
+ ignorable += [:modify_date, :create_date, :date_time_original, :nd_filter] if Exiftoolr.exiftool_version <= 8.2
65
65
  ignorable
66
66
  end.include?(key) || key.to_s =~ TRANSLATED_KEY
67
67
  end
metadata CHANGED
@@ -1,61 +1,50 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: exiftoolr
3
- version: !ruby/object:Gem::Version
4
- hash: 17
5
- prerelease:
6
- segments:
7
- - 0
8
- - 0
9
- - 7
10
- version: 0.0.7
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.8
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - Matthew McEachen
14
8
  autorequire:
15
9
  bindir: bin
16
10
  cert_chain: []
17
-
18
- date: 2012-03-28 00:00:00 -07:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
11
+ date: 2013-07-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: json
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
22
20
  type: :runtime
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
- none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- hash: 3
29
- segments:
30
- - 0
31
- version: "0"
32
21
  prerelease: false
33
- name: json
34
- version_requirements: *id001
35
- - !ruby/object:Gem::Dependency
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
36
34
  type: :development
37
- requirement: &id002 !ruby/object:Gem::Requirement
38
- none: false
39
- requirements:
40
- - - ">="
41
- - !ruby/object:Gem::Version
42
- hash: 3
43
- segments:
44
- - 0
45
- version: "0"
46
35
  prerelease: false
47
- name: rake
48
- version_requirements: *id002
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
49
41
  description: Multiget ExifTool wrapper for ruby
50
- email:
42
+ email:
51
43
  - matthew-github@mceachen.org
52
44
  executables: []
53
-
54
45
  extensions: []
55
-
56
46
  extra_rdoc_files: []
57
-
58
- files:
47
+ files:
59
48
  - .gitignore
60
49
  - .travis.yml
61
50
  - Gemfile
@@ -74,41 +63,31 @@ files:
74
63
  - test/iPhone 4S.jpg
75
64
  - test/iPhone 4S.jpg.yaml
76
65
  - test/test_exiftoolr.rb
77
- has_rdoc: true
78
66
  homepage: https://github.com/mceachen/exiftoolr
79
67
  licenses: []
80
-
68
+ metadata: {}
81
69
  post_install_message:
82
70
  rdoc_options: []
83
-
84
- require_paths:
71
+ require_paths:
85
72
  - lib
86
- required_ruby_version: !ruby/object:Gem::Requirement
87
- none: false
88
- requirements:
89
- - - ">="
90
- - !ruby/object:Gem::Version
91
- hash: 3
92
- segments:
93
- - 0
94
- version: "0"
95
- required_rubygems_version: !ruby/object:Gem::Requirement
96
- none: false
97
- requirements:
98
- - - ">="
99
- - !ruby/object:Gem::Version
100
- hash: 3
101
- segments:
102
- - 0
103
- version: "0"
104
- requirements:
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements:
105
84
  - ExifTool (see http://www.sno.phy.queensu.ca/~phil/exiftool/)
106
85
  rubyforge_project: exiftoolr
107
- rubygems_version: 1.6.2
86
+ rubygems_version: 2.0.2
108
87
  signing_key:
109
- specification_version: 3
88
+ specification_version: 4
110
89
  summary: Multiget ExifTool wrapper for ruby
111
- test_files:
90
+ test_files:
112
91
  - test/Canon 20D.jpg
113
92
  - test/Canon 20D.jpg.yaml
114
93
  - test/Droid X.jpg