module NoaaWeatherClient::Services::FindNearestStation

Public Class Methods

find(lat, lon, stations, options = {}) click to toggle source
# File lib/noaa_weather_client/services/find_nearest_station.rb, line 6
def self.find(lat, lon, stations, options = {})
  calc = options.fetch(:calculator, CalculateDistanceBetweenLatLon)
  filter = options.fetch(:filter, nil)
  count = options.fetch(:count, 1)
  stations.select!(&filter) if filter
  stations.sort_by! { |s| calc.get_distance(lat, lon, s.latitude, s.longitude) }
  count == 1 ? stations.first : stations.take(count)
end