Class: PhotoGeoloader

Inherits:
Object
  • Object
show all
Defined in:
lib/photo_geoloader.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#attributesObject

Returns the value of attribute attributes.



5
6
7
# File 'lib/photo_geoloader.rb', line 5

def attributes
  @attributes
end

#dataObject

Returns the value of attribute data.



5
6
7
# File 'lib/photo_geoloader.rb', line 5

def data
  @data
end

#photo_pathObject

Returns the value of attribute photo_path.



5
6
7
# File 'lib/photo_geoloader.rb', line 5

def photo_path
  @photo_path
end

#positionObject

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_dataObject



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