From a733e9ee92e12a57dd8159c9374233e6c7fdc193 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Rodrigo?= Date: Tue, 12 Nov 2024 10:49:31 +0100 Subject: [PATCH] Slugify Apidea source ids --- datasources/connectors/apidae.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/datasources/connectors/apidae.rb b/datasources/connectors/apidae.rb index 6c710a9..6786461 100644 --- a/datasources/connectors/apidae.rb +++ b/datasources/connectors/apidae.rb @@ -8,6 +8,17 @@ class Apidae < Connector + def slugify(s) + s = s.gsub(/\s+/, ' ') + s.strip! + s.gsub!(' ', '-') + s.gsub!('&', 'and') + s = I18n.transliterate(s) + s.gsub!(/[^\w-]/u, '') + s.gsub!(/-+/, '-') + s.mb_chars.downcase.to_s + end + def setup(kiba) kiba.source(MetadataSource, @job_id, @job_id, nil, MetadataSource::Settings.from_hash({ 'schema' => [ @@ -33,7 +44,7 @@ def setup(kiba) selections.select{ |selection| @source_filter.nil? || selection['nom'].start_with?(@source_filter) }.each{ |selection| - destination_id = "#{selection['id']}-#{selection['nom']}" + destination_id = "#{selection['id']}-#{slugify(selection['nom'])}" name = selection['libelle'].transform_keys{ |key| key[('libelle'.size)..].downcase } kiba.source(