Class: GpxDoctor::ElevationClient

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

Constant Summary collapse

MAX_REQUEST_LINE_BYTES =
1024
LOOKUP_PATH =
'/api/v1/lookup'

Instance Method Summary collapse

Constructor Details

#initialize(config = nil) ⇒ ElevationClient

Returns a new instance of ElevationClient.



12
13
14
15
16
17
# File 'lib/gpx_doctor/elevation_client.rb', line 12

def initialize(config = nil)
  config    = config || GpxDoctor.configuration
  @base_url = config.elevation_server_url
  @user     = config.elevation_server_user
  @password = config.elevation_server_password
end

Instance Method Details

#enhance(waypoints) ⇒ Object

Enhances waypoints that have nil ele with elevation from the server. Mutates the waypoints in place.



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/gpx_doctor/elevation_client.rb', line 21

def enhance(waypoints)
  missing = waypoints.select { |wp| wp.ele.nil? }
  return if missing.empty?

  batches(missing).each do |batch|
    elevations = fetch_elevations(batch)
    batch.zip(elevations).each do |wp, elev|
      wp.ele = elev if elev
    end
  end
end