Class: Photo::EXIFData
- Inherits:
-
Object
- Object
- Photo::EXIFData
- Defined in:
- lib/models/photo.rb
Constant Summary collapse
- EXIF_TRANSLATIONS =
{ :title => ['Title','ObjectName'], :focal_length => ['FocalLength'], :iso => ['ISO'], :height => ['ImageHeight'], :width => ['ImageWidth'], :shutter_speed => ['ShutterSpeedValue'], :f_stop => ['ApertureValue'], :lens => ['Lens','LensType'], :camera => ['Model'], :date => ['DateTimeOriginal'], :caption => ['Description','ImageDescription','Caption-Abstract'], :tags => ['Keywords','Subject'], :location => ['Location'], }
- EXIF_TRANSFORMATIONS =
{ #:date => lambda{|exif_value| exif_value.to_s.split('-').shift}, :shutter_speed => lambda{|exif_value| exif_value.to_s.gsub(/1\//,'')}, :focal_length => lambda{|exif_value| exif_value.to_s.gsub(/\.([\d]{1,})?\s?.+$/,'')}, :tags => lambda{|exif_value| (exif_value.is_a?(Array) ? exif_value.join(',') : exif_value).gsub(/["']+/,'').gsub(/\s+?,\s+?/,',').split(',').collect(&:strip).collect(&:downcase)} }
Instance Method Summary collapse
- #[](key) ⇒ Object
-
#initialize(exif_data, logger) ⇒ EXIFData
constructor
A new instance of EXIFData.
Constructor Details
#initialize(exif_data, logger) ⇒ EXIFData
Returns a new instance of EXIFData.
141 142 143 144 |
# File 'lib/models/photo.rb', line 141 def initialize(exif_data,logger) @exif_data = exif_data @logger = logger end |
Instance Method Details
#[](key) ⇒ Object
146 147 148 149 150 151 152 153 154 |
# File 'lib/models/photo.rb', line 146 def [](key) EXIF_TRANSLATIONS[key.to_sym].each do |exif_key_name| exif_value = @exif_data[exif_key_name.to_s] if !exif_value.nil? && exif_value != false && exif_value != '' && exif_value != 'false' && exif_value != 'nil' return EXIF_TRANSFORMATIONS[key] ? EXIF_TRANSFORMATIONS[key].call(exif_value) : exif_value end end false end |