diff --git a/app/lib/carto/bano/address_retriever.rb b/app/lib/carto/bano/address_retriever.rb index 83fb03de3..895320adc 100644 --- a/app/lib/carto/bano/address_retriever.rb +++ b/app/lib/carto/bano/address_retriever.rb @@ -25,8 +25,8 @@ module Carto return [] end - result['features'].inject([]) do |acc, feature| - acc.push feature['properties']['label'] + result['features'].map do |feature| + feature['properties']['label'] end rescue TypeError, JSON::ParserError [] diff --git a/app/lib/carto/sgmap/cadastre/adapter.rb b/app/lib/carto/sgmap/cadastre/adapter.rb index 6c49a9af3..ae9d0bce5 100644 --- a/app/lib/carto/sgmap/cadastre/adapter.rb +++ b/app/lib/carto/sgmap/cadastre/adapter.rb @@ -8,11 +8,11 @@ class CARTO::SGMAP::Cadastre::Adapter end def to_params - data_source[:features].inject([]) do |acc, feature| + data_source[:features].map do |feature| tmp = filter_properties feature[:properties] tmp[:geometry] = feature[:geometry] - acc << tmp + tmp end end diff --git a/app/models/champ.rb b/app/models/champ.rb index d5932bef6..82e14e40e 100644 --- a/app/models/champ.rb +++ b/app/models/champ.rb @@ -48,15 +48,15 @@ class Champ < ActiveRecord::Base end def self.regions - JSON.parse(Carto::GeoAPI::Driver.regions).sort_by { |e| e['nom'] }.inject([]) { |acc, liste| acc.push(liste['nom']) } + JSON.parse(Carto::GeoAPI::Driver.regions).sort_by { |e| e['nom'] }.map { |liste| liste['nom'] } end def self.departements - JSON.parse(Carto::GeoAPI::Driver.departements).inject([]) { |acc, liste| acc.push(liste['code'] + ' - ' + liste['nom']) }.push('99 - Étranger') + JSON.parse(Carto::GeoAPI::Driver.departements).map { |liste| liste['code'] + ' - ' + liste['nom'] }.push('99 - Étranger') end def self.pays - JSON.parse(Carto::GeoAPI::Driver.pays).inject([]) { |acc, liste| acc.push(liste['nom']) } + JSON.parse(Carto::GeoAPI::Driver.pays).map { |liste| liste['nom'] } end def to_s diff --git a/app/services/module_api_carto_service.rb b/app/services/module_api_carto_service.rb index e1120c316..492a2543d 100644 --- a/app/services/module_api_carto_service.rb +++ b/app/services/module_api_carto_service.rb @@ -32,10 +32,10 @@ class ModuleApiCartoService end def self.generate_cadastre coordinates - (coordinates.inject([]) { |acc, coordinate| - acc << CARTO::SGMAP::Cadastre::Adapter.new( + coordinates.flat_map do |coordinate| + CARTO::SGMAP::Cadastre::Adapter.new( coordinate.map { |element| [element['lng'], element['lat']] } ).to_params - }).flatten + end end end