Class: PhotoGeoloader
- Inherits:
-
Object
- Object
- PhotoGeoloader
- Defined in:
- lib/photo_geoloader.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#data ⇒ Object
Returns the value of attribute data.
-
#photo_path ⇒ Object
Returns the value of attribute photo_path.
-
#position ⇒ Object
Returns the value of attribute position.
Instance Method Summary collapse
-
#initialize(photo_path, attributes = [:latitude, :longitude, :altitude]) ⇒ PhotoGeoloader
constructor
A new instance of PhotoGeoloader.
- #load_exif_data ⇒ Object
- #place_attributes(model) ⇒ Object
Constructor Details
#initialize(photo_path, attributes = [:latitude, :longitude, :altitude]) ⇒ PhotoGeoloader
Returns a new instance of PhotoGeoloader.
7 8 9 10 11 12 |
# File 'lib/photo_geoloader.rb', line 7 def initialize(photo_path, attributes = [:latitude, :longitude, :altitude]) self.photo_path = photo_path self.attributes = attributes self.position = {} load_exif_data end |
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
5 6 7 |
# File 'lib/photo_geoloader.rb', line 5 def attributes @attributes end |
#data ⇒ Object
Returns the value of attribute data.
5 6 7 |
# File 'lib/photo_geoloader.rb', line 5 def data @data end |
#photo_path ⇒ Object
Returns the value of attribute photo_path.
5 6 7 |
# File 'lib/photo_geoloader.rb', line 5 def photo_path @photo_path end |
#position ⇒ Object
Returns the value of attribute position.
5 6 7 |
# File 'lib/photo_geoloader.rb', line 5 def position @position end |
Instance Method Details
#load_exif_data ⇒ Object
14 15 16 17 18 19 |
# File 'lib/photo_geoloader.rb', line 14 def load_exif_data self.data = EXIFR::JPEG.new(photo_path).exif.to_a.first attributes.each do |attr| self.position[attr.to_sym] = data.fields[:gps].fields["gps_#{attr}".to_sym].to_f end end |
#place_attributes(model) ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/photo_geoloader.rb', line 21 def place_attributes(model) success = false attributes.each do |attr| if model.respond_to? attr model.send "#{attr}=".to_sym, position[attr.to_sym] success = true end end success end |