Class: ExifGpsInjector::Kml

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

Overview

Kml

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Kml

Returns a new instance of Kml.



7
8
9
10
11
12
# File 'lib/exif_gps_injector/kml.rb', line 7

def initialize(options = {})
  @dir = options.delete(:dir)
  @max_distance_time = options.delete(:max_distance_time) || 2.minutes
  @list = {}
  Dir.glob("#{@dir}/*.kml").each { |kml| @list.merge!(extract_list_from_kml(File.read(kml))) }
end

Instance Attribute Details

#listObject (readonly)

Returns the value of attribute list.



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

def list
  @list
end

#max_distance_timeObject

Returns the value of attribute max_distance_time.



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

def max_distance_time
  @max_distance_time
end

Instance Method Details

#locate_at(date) ⇒ Object



14
15
16
17
18
# File 'lib/exif_gps_injector/kml.rb', line 14

def locate_at(date)
  date = DateTime.parse(date).utc
  @list.select { |key, _value| key <= date && key >= date - @max_distance_time }.to_a.last.try(:last) ||
    @list.select { |key, _value| key >= date && key <= date + @max_distance_time }.to_a.first.try(:last)
end