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 [] return []
end end
result['features'].inject([]) do |acc, feature| result['features'].map do |feature|
acc.push feature['properties']['label'] feature['properties']['label']
end end
rescue TypeError, JSON::ParserError rescue TypeError, JSON::ParserError
[] []

View file

@ -8,11 +8,11 @@ class CARTO::SGMAP::Cadastre::Adapter
end end
def to_params def to_params
data_source[:features].inject([]) do |acc, feature| data_source[:features].map do |feature|
tmp = filter_properties feature[:properties] tmp = filter_properties feature[:properties]
tmp[:geometry] = feature[:geometry] tmp[:geometry] = feature[:geometry]
acc << tmp tmp
end end
end end

View file

@ -48,15 +48,15 @@ class Champ < ActiveRecord::Base
end end
def self.regions 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 end
def self.departements 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 end
def self.pays 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 end
def to_s def to_s

View file

@ -32,10 +32,10 @@ class ModuleApiCartoService
end end
def self.generate_cadastre coordinates def self.generate_cadastre coordinates
(coordinates.inject([]) { |acc, coordinate| coordinates.flat_map do |coordinate|
acc << CARTO::SGMAP::Cadastre::Adapter.new( CARTO::SGMAP::Cadastre::Adapter.new(
coordinate.map { |element| [element['lng'], element['lat']] } coordinate.map { |element| [element['lng'], element['lat']] }
).to_params ).to_params
}).flatten end
end end
end end