2023-10-27 14:20:40 +02:00
|
|
|
|
class Champs::RNFChamp < Champ
|
|
|
|
|
store_accessor :data, :title, :email, :phone, :createdAt, :updatedAt, :dissolvedAt, :address, :status
|
|
|
|
|
|
|
|
|
|
def rnf_id
|
|
|
|
|
external_id
|
|
|
|
|
end
|
|
|
|
|
|
2023-11-22 12:35:30 +01:00
|
|
|
|
def value
|
|
|
|
|
rnf_id
|
|
|
|
|
end
|
|
|
|
|
|
2023-10-27 14:20:40 +02:00
|
|
|
|
def fetch_external_data
|
|
|
|
|
RNFService.new.(rnf_id:)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def fetch_external_data?
|
|
|
|
|
true
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def poll_external_data?
|
|
|
|
|
true
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def blank?
|
|
|
|
|
rnf_id.blank?
|
|
|
|
|
end
|
2023-11-21 11:02:33 +01:00
|
|
|
|
|
2024-04-02 17:05:44 +02:00
|
|
|
|
def for_export(path = :value)
|
|
|
|
|
case path
|
|
|
|
|
when :value
|
|
|
|
|
rnf_id
|
|
|
|
|
when :departement
|
|
|
|
|
departement_code_and_name
|
|
|
|
|
when :code_insee
|
|
|
|
|
commune&.fetch(:code)
|
|
|
|
|
when :address
|
|
|
|
|
full_address
|
|
|
|
|
when :nom
|
|
|
|
|
title
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def for_tag(path = :value)
|
|
|
|
|
case path
|
|
|
|
|
when :value
|
|
|
|
|
rnf_id
|
|
|
|
|
when :departement
|
|
|
|
|
departement_code_and_name || ''
|
|
|
|
|
when :code_insee
|
|
|
|
|
commune&.fetch(:code) || ''
|
|
|
|
|
when :address
|
|
|
|
|
full_address || ''
|
|
|
|
|
when :nom
|
|
|
|
|
title || ''
|
2023-11-21 11:02:33 +01:00
|
|
|
|
end
|
|
|
|
|
end
|
2023-11-17 12:48:25 +01:00
|
|
|
|
|
|
|
|
|
def code_departement
|
|
|
|
|
address.present? && address['departmentCode']
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def departement?
|
|
|
|
|
code_departement.present?
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def departement
|
|
|
|
|
if departement?
|
|
|
|
|
{ code: code_departement, name: departement_name }
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def departement_name
|
|
|
|
|
APIGeoService.departement_name(code_departement)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def departement_code_and_name
|
|
|
|
|
if departement?
|
|
|
|
|
"#{code_departement} – #{departement_name}"
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def commune_name
|
|
|
|
|
if departement?
|
2024-04-02 17:05:44 +02:00
|
|
|
|
"#{APIGeoService.commune_name(code_departement, address['cityCode'])} (#{address['postalCode']})"
|
2023-11-17 12:48:25 +01:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def commune
|
|
|
|
|
if departement?
|
|
|
|
|
city_code = address['cityCode']
|
|
|
|
|
city_name = address['cityName']
|
|
|
|
|
postal_code = address['postalCode']
|
|
|
|
|
|
2024-04-02 17:05:44 +02:00
|
|
|
|
commune_name = APIGeoService.commune_name(code_departement, city_code)
|
|
|
|
|
commune_code = APIGeoService.commune_code(code_departement, city_name)
|
2023-11-17 12:48:25 +01:00
|
|
|
|
|
|
|
|
|
if commune_name.present?
|
|
|
|
|
{
|
|
|
|
|
code: city_code,
|
|
|
|
|
name: commune_name
|
|
|
|
|
}
|
|
|
|
|
elsif commune_code.present?
|
|
|
|
|
{
|
|
|
|
|
code: commune_code,
|
|
|
|
|
name: city_name
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
code: city_code,
|
|
|
|
|
name: city_name
|
|
|
|
|
}
|
|
|
|
|
end.merge(postal_code:)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def rnf_address
|
|
|
|
|
if departement?
|
|
|
|
|
{
|
|
|
|
|
label: address["label"],
|
|
|
|
|
type: address["type"],
|
|
|
|
|
street_address: address["streetAddress"],
|
|
|
|
|
street_number: address["streetNumber"],
|
|
|
|
|
street_name: address["streetName"],
|
|
|
|
|
postal_code: address["postalCode"],
|
|
|
|
|
city_name: address["cityName"],
|
|
|
|
|
city_code: address["cityCode"],
|
|
|
|
|
department_name: address["departmentName"],
|
|
|
|
|
department_code: address["departmentCode"],
|
|
|
|
|
region_name: address["regionName"],
|
|
|
|
|
region_code: address["regionCode"]
|
2024-03-11 10:49:43 +01:00
|
|
|
|
}.with_indifferent_access
|
2023-11-17 12:48:25 +01:00
|
|
|
|
end
|
|
|
|
|
end
|
2024-01-31 17:28:00 +01:00
|
|
|
|
|
|
|
|
|
def full_address
|
|
|
|
|
if address.present?
|
|
|
|
|
address['label']
|
|
|
|
|
end
|
|
|
|
|
end
|
2023-10-27 14:20:40 +02:00
|
|
|
|
end
|