decoupage_administratif 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +55 -0
- data/CHANGELOG.md +35 -0
- data/LICENSE.txt +21 -0
- data/README.md +320 -0
- data/Rakefile +14 -0
- data/data/communes.json +37640 -0
- data/data/departements.json +111 -0
- data/data/epci.json +1257 -0
- data/data/regions.json +28 -0
- data/lib/decoupage_administratif/base_model.rb +60 -0
- data/lib/decoupage_administratif/commune.rb +82 -0
- data/lib/decoupage_administratif/config.rb +47 -0
- data/lib/decoupage_administratif/departement.rb +51 -0
- data/lib/decoupage_administratif/epci.rb +61 -0
- data/lib/decoupage_administratif/parser.rb +41 -0
- data/lib/decoupage_administratif/railtie.rb +11 -0
- data/lib/decoupage_administratif/region.rb +50 -0
- data/lib/decoupage_administratif/search.rb +181 -0
- data/lib/decoupage_administratif/territory_extensions.rb +35 -0
- data/lib/decoupage_administratif/territory_strategies.rb +87 -0
- data/lib/decoupage_administratif/version.rb +7 -0
- data/lib/decoupage_administratif.rb +26 -0
- data/lib/tasks/install.rake +59 -0
- data/sig/decoupage_administratif/base_model.rbs +7 -0
- data/sig/decoupage_administratif/commune.rbs +32 -0
- data/sig/decoupage_administratif/departement.rbs +24 -0
- data/sig/decoupage_administratif/epci.rbs +23 -0
- data/sig/decoupage_administratif/parser.rbs +11 -0
- data/sig/decoupage_administratif/region.rbs +21 -0
- data/sig/decoupage_administratif/search.rbs +20 -0
- data/sig/decoupage_administratif/territory_extensions.rbs +11 -0
- data/sig/decoupage_administratif/territory_strategies.rbs +51 -0
- data/sig/decoupage_administratif.rbs +4 -0
- metadata +96 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 04b92f3a97be9ce20975c76881ed509aa608d086ffe3782e433b59ac09d2bcc9
|
4
|
+
data.tar.gz: 7006ac29d38e8ddb3d96b2959c9b77256a3949ae295020e0eb90461d0f33d36a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3c92fc51aa2605f90ec9bf5f7b60e5b42b3acd8f1b0d06792dba10e22bd26daa354e2b4aff324b19e35b2d30fb3ce2611169400ae7dca0f4eb993723d39d72de
|
7
|
+
data.tar.gz: af795631f1346c222f2533a5a269557aed1305240bb2f25ff207f96a8298cf0d9db8fa03525f2acec7bf91889758b0a13492d620db157c3b274c443a74d31f92
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require:
|
2
|
+
- rubocop-rake
|
3
|
+
- rubocop-rspec
|
4
|
+
|
5
|
+
AllCops:
|
6
|
+
TargetRubyVersion: 3.0
|
7
|
+
NewCops: enable
|
8
|
+
Exclude:
|
9
|
+
- 'vendor/**/*'
|
10
|
+
- 'db/schema.rb'
|
11
|
+
- 'bin/*'
|
12
|
+
- 'pkg/**/*'
|
13
|
+
|
14
|
+
Layout/LineLength:
|
15
|
+
Enabled: false
|
16
|
+
|
17
|
+
Metrics/AbcSize:
|
18
|
+
Enabled: false
|
19
|
+
|
20
|
+
Metrics/BlockLength:
|
21
|
+
Enabled: false
|
22
|
+
|
23
|
+
Metrics/ClassLength:
|
24
|
+
Enabled: false
|
25
|
+
|
26
|
+
Metrics/MethodLength:
|
27
|
+
Enabled: false
|
28
|
+
|
29
|
+
Style/Documentation:
|
30
|
+
Enabled: false
|
31
|
+
|
32
|
+
Style/StringLiterals:
|
33
|
+
Enabled: false
|
34
|
+
|
35
|
+
Style/StringLiteralsInInterpolation:
|
36
|
+
Enabled: false
|
37
|
+
|
38
|
+
# RSpec specific configurations
|
39
|
+
RSpec/ExampleLength:
|
40
|
+
Enabled: false
|
41
|
+
|
42
|
+
RSpec/MultipleExpectations:
|
43
|
+
Enabled: false
|
44
|
+
|
45
|
+
RSpec/MultipleMemoizedHelpers:
|
46
|
+
Enabled: false
|
47
|
+
|
48
|
+
RSpec/NamedSubject:
|
49
|
+
Enabled: false
|
50
|
+
|
51
|
+
RSpec/NestedGroups:
|
52
|
+
Max: 5
|
53
|
+
|
54
|
+
RSpec/SpecFilePathFormat:
|
55
|
+
Enabled: false
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
## [Unreleased]
|
2
|
+
|
3
|
+
## [0.1.0] - 2025-08-26
|
4
|
+
|
5
|
+
### Added
|
6
|
+
- Initial release of the DecoupageAdministratif gem
|
7
|
+
- Support for French administrative divisions:
|
8
|
+
- **Communes**: Access to 35,000+ French municipalities with codes, names, and types
|
9
|
+
- **Départements**: All French departments with their communes
|
10
|
+
- **Régions**: All French regions with departments and communes
|
11
|
+
- **EPCIs**: Intercommunal cooperation establishments with member communes
|
12
|
+
- Query API inspired by ActiveRecord:
|
13
|
+
- `find(code)`: Find by code, raises error if not found
|
14
|
+
- `find_by(attribute: value)`: Find first match, returns nil if not found
|
15
|
+
- `where(criteria)`: Filter with exact or partial matching
|
16
|
+
- `all`: Get all records
|
17
|
+
- Advanced search capabilities:
|
18
|
+
- Search territories by INSEE codes
|
19
|
+
- Find complete territories (departments, regions, EPCIs) from commune codes
|
20
|
+
- Support for partial matching and case-insensitive searches
|
21
|
+
- Territory intersection methods:
|
22
|
+
- `territory_intersects_with_insee_codes?`: Check if territory contains any of the given INSEE codes
|
23
|
+
- `territory_insee_codes`: Get all INSEE codes for a territory
|
24
|
+
- Flexible data configuration:
|
25
|
+
- Embedded data files included in the gem
|
26
|
+
- Optional custom data directory via `DECOUPAGE_DATA_DIR` environment variable
|
27
|
+
- Automatic fallback to user directory or Rails tmp
|
28
|
+
- Rake task to update data from official @etalab/decoupage-administratif package
|
29
|
+
- Performance optimizations:
|
30
|
+
- Class-level caching for communes and departments
|
31
|
+
- Efficient search algorithms for large datasets
|
32
|
+
- Full test coverage with RSpec
|
33
|
+
- YARD documentation for all public methods
|
34
|
+
- RBS type signatures for type safety
|
35
|
+
- Rubocop linting configuration
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2025 Lucien
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,320 @@
|
|
1
|
+
# DecoupageAdministratif
|
2
|
+
English version below
|
3
|
+
|
4
|
+
Gem Ruby permettant d’accéder facilement aux données du découpage administratif français (régions, départements, communes, EPCI) à partir des jeux de données de Datagouv : <https://github.com/datagouv/decoupage-administratif>.
|
5
|
+
|
6
|
+
## Territoires couverts
|
7
|
+
- Régions
|
8
|
+
- Départements
|
9
|
+
- Communes
|
10
|
+
- EPCI (Établissements Publics de Coopération Intercommunale)
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
Ajoutez la gem à votre Gemfile :
|
15
|
+
|
16
|
+
bundle add decoupage_administratif
|
17
|
+
|
18
|
+
Ou installez-la directement :
|
19
|
+
|
20
|
+
gem install decoupage_administratif
|
21
|
+
|
22
|
+
Mise à jour des données (optionnel) :
|
23
|
+
|
24
|
+
rake decoupage_administratif:update
|
25
|
+
|
26
|
+
### Configuration
|
27
|
+
|
28
|
+
**Données embarquées :** La gem inclut maintenant les données par défaut et fonctionne directement sans installation additionnelle.
|
29
|
+
|
30
|
+
**Données personnalisées :** Vous pouvez utiliser des données plus récentes en les téléchargeant :
|
31
|
+
|
32
|
+
```bash
|
33
|
+
# Mettre à jour vers les dernières données (optionnel)
|
34
|
+
rake decoupage_administratif:update
|
35
|
+
```
|
36
|
+
|
37
|
+
**Répertoire personnalisé :**
|
38
|
+
```bash
|
39
|
+
# Via variable d'environnement
|
40
|
+
export DECOUPAGE_DATA_DIR=/path/to/your/data/directory
|
41
|
+
rake decoupage_administratif:update
|
42
|
+
```
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
# Via code (pour Rails)
|
46
|
+
# config/initializers/decoupage_administratif.rb
|
47
|
+
DecoupageAdministratif::Config.data_directory = Rails.root.join('tmp', 'decoupage_data')
|
48
|
+
```
|
49
|
+
|
50
|
+
**Ordre de priorité :**
|
51
|
+
1. Données dans le répertoire personnalisé (`DECOUPAGE_DATA_DIR`)
|
52
|
+
2. Données dans `~/.local/share/decoupage_administratif/`
|
53
|
+
3. **Données embarquées dans la gem** (fallback automatique)
|
54
|
+
|
55
|
+
## Utilisation
|
56
|
+
|
57
|
+
Exemple d’utilisation basique :
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
# Lister toutes les régions
|
61
|
+
DecoupageAdministratif::Region.all
|
62
|
+
|
63
|
+
# Trouver une commune par code INSEE
|
64
|
+
# Une commune a un commune_type qui peut être `commune-actuelle`, `commune-deleguee` (anciennes communes) ou `commune-associee` (anciennes communes avec un statut spécial)
|
65
|
+
commune = DecoupageAdministratif::Commune.find('75056')
|
66
|
+
puts commune.nom # => "Paris"
|
67
|
+
|
68
|
+
# Lister les départements d'une région
|
69
|
+
DecoupageAdministratif::Region.find('84').departements
|
70
|
+
|
71
|
+
# Lister toutes les communes actuelles d’un département
|
72
|
+
departement = DecoupageAdministratif::Departement.find('72')
|
73
|
+
puts departement.communes
|
74
|
+
|
75
|
+
# Trouver un EPCI par son SIREN
|
76
|
+
epci = DecoupageAdministratif::Epci.find('200054781')
|
77
|
+
puts epci.nom
|
78
|
+
|
79
|
+
# Lister les communes d’un EPCI
|
80
|
+
puts epci.communes
|
81
|
+
|
82
|
+
# Rechercher une commune par nom (insensible à la casse)
|
83
|
+
DecoupageAdministratif::Commune.where('paris', case_insensitive: true)
|
84
|
+
|
85
|
+
# Lister les départements d'une région
|
86
|
+
region = DecoupageAdministratif::Region.find_by(nom: 'Bretagne')
|
87
|
+
puts region.departements
|
88
|
+
```
|
89
|
+
|
90
|
+
### Extensions territoriales
|
91
|
+
|
92
|
+
La gem propose des méthodes pour vérifier la correspondance entre territoires et listes de codes INSEE :
|
93
|
+
|
94
|
+
```ruby
|
95
|
+
# Vérifier si un territoire contient au moins une commune d'une liste
|
96
|
+
commune_codes = ['75001', '75002', '69001']
|
97
|
+
departement = DecoupageAdministratif::Departement.find('75')
|
98
|
+
departement.territory_intersects_with_insee_codes?(commune_codes) # => true
|
99
|
+
|
100
|
+
# Obtenir tous les codes INSEE des communes d'un territoire
|
101
|
+
departement.territory_insee_codes # => ["75001", "75002", "75003", ...]
|
102
|
+
```
|
103
|
+
|
104
|
+
## Développement
|
105
|
+
|
106
|
+
Build la gem après avoir cloné le dépôt :
|
107
|
+
|
108
|
+
gem build decoupage_administratif.gemspec
|
109
|
+
|
110
|
+
Installer la gem localement :
|
111
|
+
|
112
|
+
bundle exec rake install
|
113
|
+
|
114
|
+
Vérifier la version installée :
|
115
|
+
|
116
|
+
ruby -r 'decoupage_administratif' -e 'puts DecoupageAdministratif::VERSION'
|
117
|
+
|
118
|
+
Mettre à jour les données (optionnel) :
|
119
|
+
|
120
|
+
rake decoupage_administratif:update
|
121
|
+
|
122
|
+
Pour lancer les tests :
|
123
|
+
|
124
|
+
rake spec
|
125
|
+
|
126
|
+
Pour une console interactive :
|
127
|
+
|
128
|
+
bin/console
|
129
|
+
|
130
|
+
Puis importer la gem :
|
131
|
+
|
132
|
+
require 'decoupage_administratif'
|
133
|
+
|
134
|
+
Pour publier une nouvelle version :
|
135
|
+
|
136
|
+
- Mettez à jour le numéro de version dans `lib/decoupage_administratif/version.rb`
|
137
|
+
- Exécutez :
|
138
|
+
|
139
|
+
bundle exec rake release
|
140
|
+
|
141
|
+
### Yard
|
142
|
+
|
143
|
+
Cette gem utilise [Yard](https://yardoc.org/) pour la documentation. Pour générer la documentation, exécutez :
|
144
|
+
|
145
|
+
yard doc
|
146
|
+
|
147
|
+
pour lancer le serveur de documentation, exécutez :
|
148
|
+
|
149
|
+
yard server
|
150
|
+
|
151
|
+
Vous pouvez ensuite accéder à la documentation à l'adresse : <http://localhost:8808>.
|
152
|
+
|
153
|
+
## Contribution
|
154
|
+
|
155
|
+
Les issues et pull requests sont les bienvenues sur : <https://github.com/BetaGouv/decoupage_administratif>
|
156
|
+
|
157
|
+
## Licence
|
158
|
+
|
159
|
+
Ce projet est sous licence [MIT](https://opensource.org/licenses/MIT).
|
160
|
+
|
161
|
+
Données : © Etalab, disponibles sous licence ouverte.
|
162
|
+
|
163
|
+
## English version
|
164
|
+
|
165
|
+
Ruby gem to easily access French administrative division data (regions, departments, municipalities, EPCI) from official datasets: <https://github.com/datagouv/decoupage-administratif>.
|
166
|
+
|
167
|
+
## Covered territories
|
168
|
+
- Regions
|
169
|
+
- Departments
|
170
|
+
- Municipalities (communes)
|
171
|
+
- EPCI (Public Establishments for Inter-municipal Cooperation)
|
172
|
+
|
173
|
+
## Installation
|
174
|
+
|
175
|
+
Add the gem to your Gemfile:
|
176
|
+
|
177
|
+
bundle add decoupage_administratif
|
178
|
+
|
179
|
+
Or install it directly:
|
180
|
+
|
181
|
+
gem install decoupage_administratif
|
182
|
+
|
183
|
+
Update data files (optional):
|
184
|
+
|
185
|
+
rake decoupage_administratif:update
|
186
|
+
|
187
|
+
### Configuration
|
188
|
+
|
189
|
+
**Embedded data:** The gem now includes default data and works directly without additional installation.
|
190
|
+
|
191
|
+
**Custom data:** You can use more recent data by downloading it:
|
192
|
+
|
193
|
+
```bash
|
194
|
+
# Update to latest data (optional)
|
195
|
+
rake decoupage_administratif:update
|
196
|
+
```
|
197
|
+
|
198
|
+
**Custom directory:**
|
199
|
+
```bash
|
200
|
+
# Via environment variable
|
201
|
+
export DECOUPAGE_DATA_DIR=/path/to/your/data/directory
|
202
|
+
rake decoupage_administratif:update
|
203
|
+
```
|
204
|
+
|
205
|
+
```ruby
|
206
|
+
# Via code (for Rails)
|
207
|
+
# config/initializers/decoupage_administratif.rb
|
208
|
+
DecoupageAdministratif::Config.data_directory = Rails.root.join('tmp', 'decoupage_data')
|
209
|
+
```
|
210
|
+
|
211
|
+
**Priority order:**
|
212
|
+
1. Data in custom directory (`DECOUPAGE_DATA_DIR`)
|
213
|
+
2. Data in `~/.local/share/decoupage_administratif/`
|
214
|
+
3. **Embedded data in the gem** (automatic fallback)
|
215
|
+
|
216
|
+
## Usage
|
217
|
+
|
218
|
+
Basic usage example:
|
219
|
+
|
220
|
+
```ruby
|
221
|
+
# List all regions
|
222
|
+
DecoupageAdministratif::Region.all
|
223
|
+
|
224
|
+
# Find a municipality by INSEE code
|
225
|
+
# A municipality has a `commune_type` which can be :commune_actuelle (current municipalities), :commune_deleguee (former municipalities), or :commune_associee (former municipalities with a special status)
|
226
|
+
commune = DecoupageAdministratif::Commune.find('75056')
|
227
|
+
puts commune.nom # => "Paris"
|
228
|
+
|
229
|
+
# List departments of a region
|
230
|
+
DecoupageAdministratif::Region.find('84').departements
|
231
|
+
|
232
|
+
# List all current municipalities of a department
|
233
|
+
departement = DecoupageAdministratif::Departement.find('72')
|
234
|
+
puts departement.communes
|
235
|
+
|
236
|
+
# Find an EPCI by its SIREN
|
237
|
+
epci = DecoupageAdministratif::Epci.find('200054781')
|
238
|
+
puts epci.nom
|
239
|
+
|
240
|
+
# List municipalities of an EPCI
|
241
|
+
puts epci.communes
|
242
|
+
|
243
|
+
# Search for a municipality by name (case-insensitive)
|
244
|
+
DecoupageAdministratif::Commune.where('paris', case_insensitive: true)
|
245
|
+
|
246
|
+
# List departments of a region
|
247
|
+
region = DecoupageAdministratif::Region.find_by(nom: 'Bretagne')
|
248
|
+
puts region.departements
|
249
|
+
```
|
250
|
+
|
251
|
+
### Territory extensions
|
252
|
+
|
253
|
+
The gem provides methods to check intersections between territories and INSEE code lists:
|
254
|
+
|
255
|
+
```ruby
|
256
|
+
# Check if a territory intersects with municipality INSEE codes
|
257
|
+
commune_codes = ['75001', '75002', '69001']
|
258
|
+
departement = DecoupageAdministratif::Departement.find('75')
|
259
|
+
departement.territory_intersects_with_insee_codes?(commune_codes) # => true
|
260
|
+
|
261
|
+
# Get all INSEE codes of municipalities in a territory
|
262
|
+
departement.territory_insee_codes # => ["75001", "75002", "75003", ...]
|
263
|
+
```
|
264
|
+
|
265
|
+
## Development
|
266
|
+
|
267
|
+
Build the gem after cloning the repository:
|
268
|
+
gem build decoupage_administratif.gemspec
|
269
|
+
|
270
|
+
Install the gem locally:
|
271
|
+
|
272
|
+
bundle exec rake install
|
273
|
+
|
274
|
+
Check the installed version:
|
275
|
+
|
276
|
+
ruby -r 'decoupage_administratif' -e 'puts DecoupageAdministratif::VERSION'
|
277
|
+
|
278
|
+
Update the data:
|
279
|
+
|
280
|
+
rake decoupage_administratif:update
|
281
|
+
|
282
|
+
To run the tests:
|
283
|
+
rake spec
|
284
|
+
|
285
|
+
For an interactive console :
|
286
|
+
|
287
|
+
bin/console
|
288
|
+
|
289
|
+
Then import the gem :
|
290
|
+
|
291
|
+
require 'decoupage_administratif'
|
292
|
+
|
293
|
+
To publish a new version :
|
294
|
+
|
295
|
+
- Update the version number in `lib/decoupage_administratif/version.rb`
|
296
|
+
- Run :
|
297
|
+
|
298
|
+
bundle exec rake release
|
299
|
+
|
300
|
+
### Yard
|
301
|
+
|
302
|
+
This gem uses [Yard](https://yardoc.org/) for documentation. To generate the documentation, run:
|
303
|
+
|
304
|
+
yard doc
|
305
|
+
|
306
|
+
to start the documentation server, run:
|
307
|
+
|
308
|
+
yard server
|
309
|
+
|
310
|
+
You can then access the documentation at: <http://localhost:8808>.
|
311
|
+
|
312
|
+
## Contribution
|
313
|
+
|
314
|
+
Issues and pull requests are welcome at : <https://github.com/BetaGouv/decoupage_administratif>
|
315
|
+
|
316
|
+
## License
|
317
|
+
|
318
|
+
This project is licensed under the [MIT](https://opensource.org/licenses/MIT) license.
|
319
|
+
|
320
|
+
Data : © Etalab, available under open license.
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
require "rspec/core/rake_task"
|
5
|
+
|
6
|
+
RSpec::Core::RakeTask.new(:spec)
|
7
|
+
|
8
|
+
require "rubocop/rake_task"
|
9
|
+
|
10
|
+
RuboCop::RakeTask.new
|
11
|
+
|
12
|
+
task default: %i[spec rubocop]
|
13
|
+
|
14
|
+
import "lib/tasks/install.rake"
|