Class: ExifGpsInjector::Media

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

Overview

Media

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ Media

Returns a new instance of Media.



6
7
8
# File 'lib/exif_gps_injector/media.rb', line 6

def initialize(file)
  @exif = MiniExiftool.new(file)
end

Instance Attribute Details

#exifObject (readonly)

Returns the value of attribute exif.



4
5
6
# File 'lib/exif_gps_injector/media.rb', line 4

def exif
  @exif
end

Instance Method Details

#locationObject



27
28
29
# File 'lib/exif_gps_injector/media.rb', line 27

def location
  { latitude: @exif.gps_latitude, longitude: @exif.gps_longitude }
end

#location=(options) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/exif_gps_injector/media.rb', line 31

def location=(options)
  @exif.gps_latitude = options[:gps_latitude]
  @exif.gps_longitude = options[:gps_longitude]
  @exif.gps_altitude = options[:gps_altitude] || 0
  @exif.gps_latitude_ref = options[:gps_latitude_ref] || 'South'
  @exif.gps_longitude_ref = options[:gps_longitude_ref] || 'West'
  @exif.save
end

#original_date_timeObject



14
15
16
# File 'lib/exif_gps_injector/media.rb', line 14

def original_date_time
  @original_date_time ||= @exif.date_time_original || @exif.create_date || @exif.modify_date
end

#original_date_time=(value) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/exif_gps_injector/media.rb', line 18

def original_date_time=(value)
  date = DateTime.parse(value).strftime
  @exif.date_time_original = date
  @exif.create_date = date
  @exif.modify_date = date
  @exif.save
  value
end

#tagsObject



10
11
12
# File 'lib/exif_gps_injector/media.rb', line 10

def tags
  @exif.tags.map { |e| [e, @exif[e]] }.to_h
end