lib/movlog/airport.rb in movlog-0.4.1 vs lib/movlog/airport.rb in movlog-0.4.2

- old
+ new

@@ -20,28 +20,46 @@ new(data) end def airports return @airports if @airports - @airports = load_airport(GeonamesApi.near_airports(lat: @lat, lng: @lng)) + load_airports(GeonamesApi.near_airports(lat: @lat, lng: @lng)) end private def load_geocode(data) data = data['geometry']['location'] @lat = data['lat'].to_f @lng = data['lng'].to_f end - def load_airport(airports) - airports.map do |ap| + def load_airports(airports) + @airports = airports.map do |ap| if ap['name'].include? 'Air' - { - name: ap['name'], country_code: ap['countryCode'], - lat: ap['lat'].to_f, lng: ap['lng'].to_f - } + airport_hash(ap) end end.compact + @airports = sort_airports + end + + def sort_airports + inter = [] + nomal = [] + @airports.each do |ap| + if ap[:name].include? 'International' + inter << ap + elsif nomal.length < 5 + nomal << ap + end + end + sorted_airports = inter + nomal + end + + def airport_hash(ap) + { + name: ap['name'], country_code: ap['countryCode'], + lat: ap['lat'].to_f, lng: ap['lng'].to_f + } end end end