Use map instead of inject

This commit is contained in:
gregoirenovel 2018-01-15 21:33:29 +01:00
parent 490a6dee4c
commit c3754a173f
4 changed files with 10 additions and 10 deletions

View file

@ -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
[]

View file

@ -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

View file

@ -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

View file

@ -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