municipitaly2 2.0.3 → 2.0.4
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 +4 -4
- data/CHANGELOG.md +7 -1
- data/Gemfile +6 -0
- data/Gemfile.lock +38 -36
- data/README.md +7 -0
- data/lib/municipitaly2/search.rb +59 -14
- data/lib/municipitaly2/version.rb +1 -1
- data/lib/municipitaly2.rb +1 -1
- data/municipitaly2.gemspec +1 -7
- data/vendor/data/municipalities.csv +7896 -7896
- data/vendor/data/provinces.csv +107 -107
- metadata +7 -80
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6d902371314d1cd9ee768b61f9ea0b3b2068725802993273fc369a9e8e155ae9
|
|
4
|
+
data.tar.gz: 3791df596b257073b1f9607ef574c102ec3bf398480f4a5982be6f2bcdbd7926
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d056647d30265de06c3e6750e8ecb3009de4c3cd03e771764fdc8b2592774478fa61988cbc7ea66e740fee3e9ec19258c6b2c05c2321e3deb78f8ef3221fee62
|
|
7
|
+
data.tar.gz: f6e9d07aaf5089cd5eb30d677b6360bd628083a02362f32403abfa1996a97eae6cf66067ac8345fcb2c6e857033958f466b7ed8b860d5aeafef156a18670f92d
|
data/CHANGELOG.md
CHANGED
|
@@ -5,9 +5,15 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [2.0.4] - 2025-09-09
|
|
9
|
+
|
|
10
|
+
- Updated database
|
|
11
|
+
- Updated gems
|
|
12
|
+
- Improved search municipalities results order
|
|
13
|
+
|
|
8
14
|
## [2.0.3] - 2024-12-17
|
|
9
15
|
|
|
10
|
-
- Search region by its name: `Municipitaly::Search.
|
|
16
|
+
- Search region by its name: `Municipitaly::Search.region_from_name('a region')`
|
|
11
17
|
- Fixed and tested specs
|
|
12
18
|
|
|
13
19
|
## [2.0.2] - 2024-12-13
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -1,75 +1,77 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
municipitaly2 (2.0.
|
|
5
|
-
csv (
|
|
4
|
+
municipitaly2 (2.0.4)
|
|
5
|
+
csv (~> 3.3.5)
|
|
6
6
|
|
|
7
7
|
GEM
|
|
8
8
|
remote: https://rubygems.org/
|
|
9
9
|
specs:
|
|
10
|
-
ast (2.4.
|
|
11
|
-
csv (3.3.
|
|
12
|
-
diff-lcs (1.
|
|
13
|
-
docile (1.4.
|
|
14
|
-
json (2.
|
|
15
|
-
language_server-protocol (3.17.0.
|
|
16
|
-
|
|
17
|
-
|
|
10
|
+
ast (2.4.3)
|
|
11
|
+
csv (3.3.5)
|
|
12
|
+
diff-lcs (1.6.2)
|
|
13
|
+
docile (1.4.1)
|
|
14
|
+
json (2.13.2)
|
|
15
|
+
language_server-protocol (3.17.0.5)
|
|
16
|
+
lint_roller (1.1.0)
|
|
17
|
+
parallel (1.27.0)
|
|
18
|
+
parser (3.3.9.0)
|
|
18
19
|
ast (~> 2.4.1)
|
|
19
20
|
racc
|
|
20
|
-
|
|
21
|
+
prism (1.4.0)
|
|
22
|
+
racc (1.8.1)
|
|
21
23
|
rainbow (3.1.1)
|
|
22
|
-
rake (13.
|
|
23
|
-
regexp_parser (2.
|
|
24
|
-
|
|
25
|
-
strscan
|
|
26
|
-
rspec (3.13.0)
|
|
24
|
+
rake (13.3.0)
|
|
25
|
+
regexp_parser (2.11.2)
|
|
26
|
+
rspec (3.13.1)
|
|
27
27
|
rspec-core (~> 3.13.0)
|
|
28
28
|
rspec-expectations (~> 3.13.0)
|
|
29
29
|
rspec-mocks (~> 3.13.0)
|
|
30
|
-
rspec-core (3.13.
|
|
30
|
+
rspec-core (3.13.5)
|
|
31
31
|
rspec-support (~> 3.13.0)
|
|
32
|
-
rspec-expectations (3.13.
|
|
32
|
+
rspec-expectations (3.13.5)
|
|
33
33
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
34
34
|
rspec-support (~> 3.13.0)
|
|
35
|
-
rspec-mocks (3.13.
|
|
35
|
+
rspec-mocks (3.13.5)
|
|
36
36
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
37
37
|
rspec-support (~> 3.13.0)
|
|
38
|
-
rspec-support (3.13.
|
|
39
|
-
rubocop (1.
|
|
38
|
+
rspec-support (3.13.5)
|
|
39
|
+
rubocop (1.80.2)
|
|
40
40
|
json (~> 2.3)
|
|
41
|
-
language_server-protocol (
|
|
41
|
+
language_server-protocol (~> 3.17.0.2)
|
|
42
|
+
lint_roller (~> 1.1.0)
|
|
42
43
|
parallel (~> 1.10)
|
|
43
44
|
parser (>= 3.3.0.2)
|
|
44
45
|
rainbow (>= 2.2.2, < 4.0)
|
|
45
|
-
regexp_parser (>=
|
|
46
|
-
|
|
47
|
-
rubocop-ast (>= 1.31.1, < 2.0)
|
|
46
|
+
regexp_parser (>= 2.9.3, < 3.0)
|
|
47
|
+
rubocop-ast (>= 1.46.0, < 2.0)
|
|
48
48
|
ruby-progressbar (~> 1.7)
|
|
49
|
-
unicode-display_width (>= 2.4.0, <
|
|
50
|
-
rubocop-ast (1.
|
|
51
|
-
parser (>= 3.3.
|
|
49
|
+
unicode-display_width (>= 2.4.0, < 4.0)
|
|
50
|
+
rubocop-ast (1.46.0)
|
|
51
|
+
parser (>= 3.3.7.2)
|
|
52
|
+
prism (~> 1.4)
|
|
52
53
|
ruby-progressbar (1.13.0)
|
|
53
54
|
simplecov (0.22.0)
|
|
54
55
|
docile (~> 1.1)
|
|
55
56
|
simplecov-html (~> 0.11)
|
|
56
57
|
simplecov_json_formatter (~> 0.1)
|
|
57
|
-
simplecov-html (0.
|
|
58
|
+
simplecov-html (0.13.2)
|
|
58
59
|
simplecov_json_formatter (0.1.4)
|
|
59
|
-
|
|
60
|
-
|
|
60
|
+
unicode-display_width (3.1.5)
|
|
61
|
+
unicode-emoji (~> 4.0, >= 4.0.4)
|
|
62
|
+
unicode-emoji (4.0.4)
|
|
61
63
|
|
|
62
64
|
PLATFORMS
|
|
63
65
|
ruby
|
|
64
66
|
x86_64-linux
|
|
65
67
|
|
|
66
68
|
DEPENDENCIES
|
|
67
|
-
bundler (~> 2.
|
|
69
|
+
bundler (~> 2.7)
|
|
68
70
|
municipitaly2!
|
|
69
|
-
rake (~> 13.
|
|
71
|
+
rake (~> 13.3)
|
|
70
72
|
rspec (~> 3.13)
|
|
71
|
-
rubocop (~> 1.
|
|
72
|
-
simplecov (~> 0.22
|
|
73
|
+
rubocop (~> 1.80)
|
|
74
|
+
simplecov (~> 0.22)
|
|
73
75
|
|
|
74
76
|
BUNDLED WITH
|
|
75
|
-
2.
|
|
77
|
+
2.7.2
|
data/README.md
CHANGED
|
@@ -14,6 +14,12 @@ Thanks to natydev for the brilliant project.
|
|
|
14
14
|
|
|
15
15
|
Add this line to your application's Gemfile:
|
|
16
16
|
|
|
17
|
+
```ruby
|
|
18
|
+
gem 'municipitaly2'
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
or if you want to use directly from the git repo:
|
|
22
|
+
|
|
17
23
|
```ruby
|
|
18
24
|
gem 'municipitaly2', git: 'https://github.com/yupswing/municipitaly2.git', branch: 'master'
|
|
19
25
|
```
|
|
@@ -252,5 +258,6 @@ Check the `tools` folder.
|
|
|
252
258
|
The tool is rought but it gets the job done. Hopefully I will improve it in the future.
|
|
253
259
|
|
|
254
260
|
### Generate vendor/data/municipalities.csv
|
|
261
|
+
|
|
255
262
|
Update links in `tools/generate.rb` (and/or data in `tools/data/istat*`) and execute
|
|
256
263
|
`./tools/generate.rb`
|
data/lib/municipitaly2/search.rb
CHANGED
|
@@ -16,11 +16,17 @@ module Municipitaly2
|
|
|
16
16
|
include DataCaller
|
|
17
17
|
|
|
18
18
|
CLASS_METHODS = %i[zone_from_code
|
|
19
|
-
region_from_name
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
region_from_name
|
|
20
|
+
region_from_istat
|
|
21
|
+
regions_from_zone_code
|
|
22
|
+
province_from_name
|
|
23
|
+
province_from_istat
|
|
24
|
+
province_from_acronym
|
|
25
|
+
provinces_from_region_istat
|
|
26
|
+
provinces_from_zone_code
|
|
27
|
+
municipalities_from_name
|
|
28
|
+
municipality_from_cadastrial
|
|
29
|
+
municipality_from_istat
|
|
24
30
|
municipalities_from_postal_code
|
|
25
31
|
municipalities_from_province_istat
|
|
26
32
|
municipalities_from_region_istat
|
|
@@ -118,8 +124,9 @@ module Municipitaly2
|
|
|
118
124
|
# example usage:
|
|
119
125
|
# province = Search.province_from_acronym('MI')
|
|
120
126
|
def province_from_acronym # :doc:
|
|
127
|
+
acronym = term.strip.upcase
|
|
121
128
|
data.provinces.find do |p|
|
|
122
|
-
p.acronym ==
|
|
129
|
+
p.acronym == acronym
|
|
123
130
|
end
|
|
124
131
|
end
|
|
125
132
|
|
|
@@ -151,6 +158,9 @@ module Municipitaly2
|
|
|
151
158
|
# Term can be a partial string and is case insensitive.
|
|
152
159
|
# The optional parameter +greedy+ [boolean] permit to serch exact term
|
|
153
160
|
# name (if false) or partial word (true by default).
|
|
161
|
+
# Matches are sorted by relevance: exact matches first, then starting with the
|
|
162
|
+
# term, then words starting with the term, then other matches. Within each
|
|
163
|
+
# group, matches are sorted by population (descending) and then by name.
|
|
154
164
|
#
|
|
155
165
|
# example usage:
|
|
156
166
|
# municipalities = Search.municipalities_from_name('monte')
|
|
@@ -161,14 +171,15 @@ module Municipitaly2
|
|
|
161
171
|
|
|
162
172
|
return [] if term_set.size < 3
|
|
163
173
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
data.municipalities
|
|
170
|
-
|
|
171
|
-
|
|
174
|
+
# regex per match "greedy" e per match esatto
|
|
175
|
+
exact_re = Regexp.new("^#{term_set}$", true)
|
|
176
|
+
search_re = greedy ? Regexp.new(term_set, true) : exact_re
|
|
177
|
+
|
|
178
|
+
# search results
|
|
179
|
+
matches = filter(data.municipalities, search_re: search_re)
|
|
180
|
+
|
|
181
|
+
# sorts results by relevance
|
|
182
|
+
matches.sort_by { |match| rank(match, term: term_set, exact_re: exact_re, greedy: greedy) }
|
|
172
183
|
end
|
|
173
184
|
|
|
174
185
|
# returns a +Municipitaly2::Municipality+ object from a <b>cadastrial
|
|
@@ -244,5 +255,39 @@ module Municipitaly2
|
|
|
244
255
|
istats.include? m.province_istat
|
|
245
256
|
end
|
|
246
257
|
end
|
|
258
|
+
|
|
259
|
+
# filters municipalities/provinces (name, name_alt required)
|
|
260
|
+
def filter(list, search_re:)
|
|
261
|
+
list.select do |item|
|
|
262
|
+
name_s = Municipitaly2.sanitize_term(item.name)
|
|
263
|
+
alt_s = item.name_alt && Municipitaly2.sanitize_term(item.name_alt)
|
|
264
|
+
(name_s =~ search_re) || (alt_s && alt_s =~ search_re)
|
|
265
|
+
end
|
|
266
|
+
end
|
|
267
|
+
|
|
268
|
+
# rank municipalities/provinces (name, name_alt, population required)
|
|
269
|
+
def rank(match, term:, exact_re:, greedy: true)
|
|
270
|
+
name_s = Municipitaly2.sanitize_term(match.name)
|
|
271
|
+
alt_s = match.name_alt && Municipitaly2.sanitize_term(match.name_alt)
|
|
272
|
+
names_s = [name_s, alt_s].compact
|
|
273
|
+
|
|
274
|
+
exact_match = names_s.any? { |n| n =~ exact_re }
|
|
275
|
+
any_word_starts = names_s.any? { |n| n.split.any? { |w| w.start_with?(term) } }
|
|
276
|
+
|
|
277
|
+
# Order: 0 = exact, 2 = any word starts, 3 = contains
|
|
278
|
+
priority = if !greedy || exact_match
|
|
279
|
+
0 # Exact match
|
|
280
|
+
# Disabled because it causes problems in some cases, like putting San Giuliano Milanese after Milazzo
|
|
281
|
+
# elsif names_s.any? { |s| s.start_with?(q) }
|
|
282
|
+
# 1 # Starts with the term
|
|
283
|
+
elsif any_word_starts
|
|
284
|
+
2 # Any word starts with the term
|
|
285
|
+
else
|
|
286
|
+
3 # Other (match inside any word)
|
|
287
|
+
end
|
|
288
|
+
|
|
289
|
+
# Priority, population (desc), name (asc)
|
|
290
|
+
[priority, -match.population.to_i, name_s]
|
|
291
|
+
end
|
|
247
292
|
end
|
|
248
293
|
end
|
data/lib/municipitaly2.rb
CHANGED
|
@@ -24,6 +24,6 @@ module Municipitaly2
|
|
|
24
24
|
# example usage:
|
|
25
25
|
# sanitized_term = Search.sanitize_term('Forlì Cesena')
|
|
26
26
|
def self.sanitize_term(term) # :doc:
|
|
27
|
-
term.strip.downcase.tr('àâçèéêìòôù', 'aaceeeioou').gsub(/[^a-z]/, '')
|
|
27
|
+
term.strip.downcase.tr('àâçèéêìòôù', 'aaceeeioou').gsub(/[^a-z ]/, '')
|
|
28
28
|
end
|
|
29
29
|
end
|
data/municipitaly2.gemspec
CHANGED
|
@@ -32,11 +32,5 @@ Gem::Specification.new do |spec|
|
|
|
32
32
|
|
|
33
33
|
spec.required_ruby_version = '>= 3.0.0'
|
|
34
34
|
|
|
35
|
-
spec.
|
|
36
|
-
spec.add_development_dependency 'rake', '~> 13.2.1'
|
|
37
|
-
spec.add_development_dependency 'rspec', '~> 3.13'
|
|
38
|
-
spec.add_development_dependency 'rubocop', '~> 1.64.1'
|
|
39
|
-
spec.add_development_dependency 'simplecov', '~> 0.22.0'
|
|
40
|
-
|
|
41
|
-
spec.add_dependency 'csv', '>= 3.3.0' # removed from stdlib in Ruby 3.4
|
|
35
|
+
spec.add_dependency 'csv', '~> 3.3.5' # removed from stdlib in Ruby 3.4
|
|
42
36
|
end
|