municipitaly2 2.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: dca402b216021d704b0236e8f9da370c16a021a6ee5222f3a5b5214dbc537ef1
4
+ data.tar.gz: 24277826ee362bcf0415676db661a7fc191b26626a7072d94c2714b2651cb742
5
+ SHA512:
6
+ metadata.gz: 6368a804a89aca144204370b882e31f97966f9dd847bdcb7b726b378fb47e0845dd9f361ecd85ad3376827fd13e28b00f5e01d1fa459b8ef22b8af8e505321b7
7
+ data.tar.gz: 4ea4e8b653bb6aafac143d97540607c2b009f777506539de4a18ff702a6216d380451992c4f25e067a159d596276d0b853e192f736b7f78bd084f1716aa94d8c
data/.gitignore ADDED
@@ -0,0 +1,16 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /vendor/bundle/
10
+ *.gem
11
+
12
+ /tools/data/*
13
+ !/tools/data/.keep
14
+
15
+ # rspec failure tracking
16
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,29 @@
1
+ AllCops:
2
+ UseCache: false
3
+ DefaultFormatter: progress
4
+ DisplayStyleGuide: true
5
+ DisplayCopNames: false
6
+ TargetRubyVersion: 3.0
7
+ NewCops: enable
8
+
9
+ Metrics/BlockLength:
10
+ Max: 50
11
+ Exclude:
12
+ - 'municipitaly2.gemspec'
13
+ - 'lib/**/*.rb'
14
+ - 'spec/**/*.rb'
15
+ Metrics/ClassLength:
16
+ Exclude:
17
+ - 'lib/municipitaly2/search.rb'
18
+
19
+ Metrics/ParameterLists:
20
+ Max: 10
21
+
22
+ Style/ClassVars:
23
+ Exclude:
24
+ - 'lib/municipitaly2/data.rb'
25
+
26
+ Style/CommentedKeyword:
27
+ Exclude:
28
+ - 'lib/municipitaly2/search.rb'
29
+
data/.travis.yml ADDED
@@ -0,0 +1,14 @@
1
+ ---
2
+ os: linux
3
+ language: ruby
4
+ rvm:
5
+ - 3.3.0
6
+ before_install: gem install bundler -v 2.5.11
7
+ before_script:
8
+ - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
9
+ - chmod +x ./cc-test-reporter
10
+ - ./cc-test-reporter before-build
11
+ script:
12
+ - bundle exec rspec
13
+ after_script:
14
+ - ./cc-test-reporter after-build --debug --exit-code $TRAVIS_TEST_RESULT --prefix /home/travis/build/natydev/municipitaly --coverage-input-type simplecov
data/CHANGELOG.md ADDED
@@ -0,0 +1,51 @@
1
+ # 🗄 Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [2.0.0] - 2024-07-25
9
+
10
+ ### Changed
11
+
12
+ - Renamed the fork to `municipitaly2`
13
+ - Bumped version to 2.0.0
14
+
15
+ ## [0.5.0] - 2024-06-20 (forked by yupswing)
16
+
17
+ ### Added
18
+
19
+ - Fixed search provinces or municipalities with diacritics
20
+ - Updated database 27-05-2024 (population data as 2021)\
21
+ - Municipalities `latitude`, `longitude` and `area` (km2)
22
+
23
+ ## [0.4.0] - 2020-11-18
24
+
25
+ ### Added
26
+
27
+ - Search province by its name: `Municipitaly::Search.province_from_name('a province')`
28
+
29
+ ## [0.3.0] - 2020-02-27
30
+
31
+ ### Added
32
+
33
+ - ISO 3166-2 code in region object `#iso3166_2` or alias `#iso3166`
34
+
35
+ ## [0.2.0] - 2020-02-24
36
+
37
+ ### Added
38
+
39
+ - ISO 3166-2 code in province object `#iso3166_2` or alias `#iso3166`
40
+
41
+ ## [0.1.0] - 2020-02-13
42
+
43
+ ### Changed
44
+
45
+ - Update municipalities data according to latest ISTAT changes (jan 2020)
46
+
47
+ ## [0.0.3] - 2020-02-10
48
+
49
+ ### Added
50
+
51
+ - The optional parameter _greedy_ in `Municipitaly::Search.municipalities_from_name`
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at natydev@localhost. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in fitbark.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,73 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ municipitaly2 (2.0.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.2)
10
+ diff-lcs (1.5.1)
11
+ docile (1.4.0)
12
+ json (2.7.2)
13
+ language_server-protocol (3.17.0.3)
14
+ parallel (1.25.1)
15
+ parser (3.3.4.0)
16
+ ast (~> 2.4.1)
17
+ racc
18
+ racc (1.8.0)
19
+ rainbow (3.1.1)
20
+ rake (13.2.1)
21
+ regexp_parser (2.9.2)
22
+ rexml (3.3.2)
23
+ strscan
24
+ rspec (3.13.0)
25
+ rspec-core (~> 3.13.0)
26
+ rspec-expectations (~> 3.13.0)
27
+ rspec-mocks (~> 3.13.0)
28
+ rspec-core (3.13.0)
29
+ rspec-support (~> 3.13.0)
30
+ rspec-expectations (3.13.1)
31
+ diff-lcs (>= 1.2.0, < 2.0)
32
+ rspec-support (~> 3.13.0)
33
+ rspec-mocks (3.13.1)
34
+ diff-lcs (>= 1.2.0, < 2.0)
35
+ rspec-support (~> 3.13.0)
36
+ rspec-support (3.13.1)
37
+ rubocop (1.64.1)
38
+ json (~> 2.3)
39
+ language_server-protocol (>= 3.17.0)
40
+ parallel (~> 1.10)
41
+ parser (>= 3.3.0.2)
42
+ rainbow (>= 2.2.2, < 4.0)
43
+ regexp_parser (>= 1.8, < 3.0)
44
+ rexml (>= 3.2.5, < 4.0)
45
+ rubocop-ast (>= 1.31.1, < 2.0)
46
+ ruby-progressbar (~> 1.7)
47
+ unicode-display_width (>= 2.4.0, < 3.0)
48
+ rubocop-ast (1.31.3)
49
+ parser (>= 3.3.1.0)
50
+ ruby-progressbar (1.13.0)
51
+ simplecov (0.22.0)
52
+ docile (~> 1.1)
53
+ simplecov-html (~> 0.11)
54
+ simplecov_json_formatter (~> 0.1)
55
+ simplecov-html (0.12.3)
56
+ simplecov_json_formatter (0.1.4)
57
+ strscan (3.1.0)
58
+ unicode-display_width (2.5.0)
59
+
60
+ PLATFORMS
61
+ ruby
62
+ x86_64-linux
63
+
64
+ DEPENDENCIES
65
+ bundler (~> 2.5.11)
66
+ municipitaly2!
67
+ rake (~> 13.2.1)
68
+ rspec (~> 3.13)
69
+ rubocop (~> 1.64.1)
70
+ simplecov (~> 0.22.0)
71
+
72
+ BUNDLED WITH
73
+ 2.5.11
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 NatyDev
4
+ Copyright (c) 2024 Simone Cingano (yupswing)
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in
14
+ all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,231 @@
1
+ # 🇮🇹 Municipitaly2
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/municipitaly2.svg)](https://badge.fury.io/rb/municipitaly2)
4
+
5
+ This gem provide various data about 🇮🇹 Italian subdivisions and municipalities. As well the entire updated list of provinces, regions and municipalities names, it provide useful codes (📯 postal code(s), 🌐 [ISTAT](https://www.istat.it/en/) codes, cadastrial code, population, ...).
6
+
7
+ ## 💾 Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'municipitaly2', git: 'https://github.com/yupswing/municipitaly2.git', branch: 'master'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ ## 👁 Scenic
20
+
21
+ These entities are present, subpoints are data attributes:
22
+
23
+ - **Zone** - NUTS 1 (it: _Zona/Ripartizione geografica_)
24
+ - name
25
+ - code (it: _codice zona_)
26
+ - **Region** - NUTS 2 (it: _Regione_)
27
+ - name
28
+ - ISTAT code (it: _codice istat_)
29
+ - **Province** - NUTS 3 (it: _Provincia_)
30
+ - name
31
+ - ISTAT code (it: _codice istat_)
32
+ - acronym (it: _sigla_)
33
+ - **Municipality** (it: _Comune_)
34
+ - name
35
+ - name_alt (alternative name)
36
+ - name_full (composite of name + name_alt if present)
37
+ - ISTAT code (it: _codice istat_)
38
+ - cadastrial code (it: _codice catastale_)
39
+ - postal code(s) (it: _codice/i postale/i_)
40
+ - population
41
+ - area (square km)
42
+ - latitude
43
+ - longitude
44
+
45
+ ## 🛠 Usage and examples
46
+
47
+ The **Municipitaly2::Search** is the principal class used to search entities.
48
+ Returned data are stored in 4 different types of entity models:
49
+
50
+ - **Municipitaly2::Zone**
51
+ - **Municipitaly2::Region**
52
+ - **Municipitaly2::Province**
53
+ - **Municipitaly2::Municipality**
54
+
55
+ Retrieve all zones (return an array of `Municipitaly2::Zone` objects):
56
+
57
+ ```ruby
58
+ # inside an irb or rails console:
59
+ require 'municipitaly2'
60
+
61
+ zones = Municipitaly2::Zone.all
62
+ # => [#<Municipitaly2::Zone:0x0000...]
63
+ ```
64
+
65
+ pick a random zone:
66
+
67
+ ```ruby
68
+ zone = zones.sample
69
+ # => #<Municipitaly2::Zone:0x00007fb8390b9f48 @name="Centro", @code="3">
70
+ ```
71
+
72
+ retrive data zone:
73
+
74
+ ```ruby
75
+ zone.name
76
+ # => "Centro"
77
+
78
+ zone.code
79
+ # => "3"
80
+ ```
81
+
82
+ all regions belongs to a zone (return an array of `Municipitaly2::Region` objects):
83
+
84
+ ```ruby
85
+ zone.regions
86
+ # => [#<Municipitaly2::Region:0x00007fb83883c550...]
87
+ ```
88
+
89
+ and so for other entities:
90
+
91
+ ```ruby
92
+ zone.provinces
93
+ # => [#<Municipitaly2::Province:0x00007fb83a1478...]
94
+
95
+ zone.municipalities
96
+ # => [#<Municipitaly2::Municipality:0x00007fb83a...]
97
+ ```
98
+
99
+ ### 🔎 Search
100
+
101
+ **Municipitaly2::Search** is the most useful and interesting class: with that you can search single or multiple entities by the name, code or other attributes.
102
+
103
+ Search municipalities **from its name**: is case insensitive and can be partial (it returns an Array):
104
+
105
+ ```ruby
106
+ municipalities = Municipitaly2::Search.municipalities_from_name('ricco')
107
+ # => [#<Municipitaly2::Municipality:0x00007d6f8c10e428
108
+ # @area=26.2065,
109
+ # @cadastrial_code="I640",
110
+ # @latitude=44.5078406,
111
+ # @longitude=8.936045,
112
+ # @name="Serra Riccò",
113
+ # @partial_istat="058",
114
+ # @population=7615,
115
+ # @postal_codes=["16010"],
116
+ # @province_istat="010">,
117
+ # #<Municipitaly2::Municipality:0x00007d6f8c106048
118
+ # @area=37.7634,
119
+ # @cadastrial_code="H275",
120
+ # @latitude=44.1555442,
121
+ # @longitude=9.7634234,
122
+ # @name="Riccò del Golfo di Spezia",
123
+ # @partial_istat="023",
124
+ # @population=3615,
125
+ # @postal_codes=["19020"],
126
+ # @province_istat="011">,
127
+ # #<Municipitaly2::Municipality:0x00007d6f8c233a38
128
+ # @area=20.3924,
129
+ # @cadastrial_code="B031",
130
+ # @latitude=45.5328242,
131
+ # @longitude=11.9685041,
132
+ # @name="Borgoricco",
133
+ # @partial_istat="013",
134
+ # @population=8906,
135
+ # @postal_codes=["35010"],
136
+ # @province_istat="028">]
137
+
138
+ municipality = municipalities.first
139
+ # => #<Municipitaly2::Municipality:0x00007fb83918483..>
140
+
141
+ municipality.name
142
+ # => "Serra Riccò"
143
+
144
+ municipality.postal_codes
145
+ # => ["16010"]
146
+ ```
147
+
148
+ from an entity object is possible to retrieve other parent objects and its attributes:
149
+
150
+ ```ruby
151
+ municipality.province_name
152
+ # => "Padova"
153
+
154
+ municipality.province_acronym
155
+ # => "PD"
156
+
157
+ municipality.province
158
+ # => #<Municipitaly2::Province:0x00007fb83a12701...>
159
+
160
+ municipality.region_name
161
+ # => "Veneto"
162
+
163
+ municipality.region
164
+ # => #<Municipitaly2::Region:0x00007fb83883cf28...>
165
+
166
+ municipality.zone
167
+ # => #<Municipitaly2::Zone:0x00007fb8390bb938...>
168
+ ```
169
+
170
+ or retrieve nested entities:
171
+
172
+ ```ruby
173
+ padua = municipality.province
174
+ # => #<Municipitaly2::Province:0x00007fb83a127010...>
175
+
176
+ padua.municipalities
177
+ # => [#<Municipitaly2::Municipality:0x00007fb83915b730...]
178
+ ```
179
+
180
+ Search municipalities **from a single postal code**:
181
+
182
+ ```ruby
183
+ municipalities = Municipitaly2::Search.municipalities_from_postal_code('50145')
184
+ # => [#<Municipitaly2::Municipality:0x00007fb83a295938 @province_istat="048", @name="Firenze"...]
185
+
186
+ florence = municipalities.first
187
+ # => #<Municipitaly2::Municipality:0x00007fb83a295938...>
188
+
189
+ florence.postal_codes
190
+ # => ["50121", "50122", "50123", "50124", "50125", "50126", "50127", "50128", "50129", "50130", "50131", "50132", "50133", "50134", "50135", "50136", "50137", "50138", "50139", "50140", "50141", "50142", "50143", "50144", "50145"]
191
+ ```
192
+
193
+ Complete list of available class and instance methods are documented inside code, is suggested to use `rdoc`, read at next point.
194
+
195
+ ### 📖 Rdoc
196
+
197
+ Clone locally this repository and run
198
+ `bundle exec rdoc` to produce complete documentation inside your local directory.
199
+
200
+ ## 🗄 Changelog
201
+
202
+ Complete list in [this section](CHANGELOG.md)
203
+
204
+ ## 🤝 Contributing
205
+
206
+ Fells free to improve or suggest new features/ideas.
207
+ Bug reports and pull requests are welcome on GitHub at https://github.com/yupswing/municipitaly2. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
208
+
209
+ If you want to contribute keep these guidelines in mind:
210
+
211
+ - Despite is an Italy focused gem, I accept only PR, issues and messages **in English** lang.
212
+ - Code must be well formatted and **offences free**, use the provided `rubocop` gem.
213
+ - Use the same **coding conventions** as the rest of the project.
214
+ - Code must be **tested** (with rspec).
215
+ - Write code according to **SOLID** Principles.
216
+
217
+ Steps to submit your code:
218
+
219
+ 1. Fork the repo.
220
+ 2. Open your feature/namespaced branch
221
+ 3. Commit your code following Github guidelines.
222
+ 4. Make a PR with an exhaustive description.
223
+
224
+ ## 📃 License
225
+
226
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
227
+
228
+ ## Data sources
229
+
230
+ - [Database dei comuni italiani by Garda Informatica](https://www.gardainformatica.it/database-comuni-italiani) (MIT Licence)
231
+ - [Dati censimento 2021 - Ministero dell'Interno](https://dait.interno.gov.it/territorio-e-autonomie-locali/sut/elenco_cens_var_comuni_italiani.php) (Public)
data/Rakefile ADDED
@@ -0,0 +1,8 @@
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
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'municipitaly2'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Municipitaly2
4
+ # Define collection
5
+ class Data
6
+ @@zones = []
7
+ @@regions = []
8
+ @@provinces = []
9
+ @@municipalities = []
10
+
11
+ def zones
12
+ if @@zones.empty?
13
+ CSV.foreach(find_csv('zones.csv'), headers: true) do |row|
14
+ @@zones << Zone.new(name: row[0], code: row[1])
15
+ end
16
+ end
17
+ @@zones
18
+ end
19
+
20
+ def regions
21
+ if @@regions.empty?
22
+ CSV.foreach(find_csv('regions.csv'), headers: true) do |row|
23
+ @@regions << Region.new(zone_code: row[0], name: row[1],
24
+ istat: row[2], partial_iso3166: row[3])
25
+ end
26
+ end
27
+ @@regions
28
+ end
29
+
30
+ def provinces
31
+ if @@provinces.empty?
32
+ CSV.foreach(find_csv('provinces.csv'), headers: true) do |row|
33
+ @@provinces << Province.new(region_istat: row[0], name: row[1],
34
+ istat: row[2], acronym: row[3])
35
+ end
36
+ end
37
+ @@provinces
38
+ end
39
+
40
+ def municipalities
41
+ if @@municipalities.empty?
42
+ CSV.foreach(find_csv('municipalities.csv'), headers: true) do |row|
43
+ @@municipalities <<
44
+ Municipality.new(province_istat: row[0],
45
+ name: row[1], name_alt: row[2], partial_istat: row[3],
46
+ cadastrial_code: row[4], postal_codes: row[5],
47
+ population: row[6], area: row[7],
48
+ latitude: row[8], longitude: row[9])
49
+ end
50
+ end
51
+ @@municipalities
52
+ end
53
+
54
+ def find_csv(file)
55
+ File.expand_path(File.join(File.dirname(__FILE__),
56
+ "../../vendor/data/#{file}"))
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Municipitaly2
4
+ # shared module to use Municipitaly2::Data instance
5
+ module DataCaller
6
+ def self.included(base)
7
+ base.send :extend, ClassMethods
8
+ end
9
+
10
+ # class methods
11
+ module ClassMethods
12
+ def data
13
+ Data.new
14
+ end
15
+ end
16
+
17
+ private
18
+
19
+ def data
20
+ @data ||= Data.new
21
+ end
22
+ end
23
+ end