municipitaly 0.0.1.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.rubocop.yml +18 -0
- data/.travis.yml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +51 -0
- data/LICENSE.txt +21 -0
- data/README.md +188 -0
- data/Rakefile +8 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/municipitaly/data.rb +59 -0
- data/lib/municipitaly/data_caller.rb +23 -0
- data/lib/municipitaly/municipality.rb +57 -0
- data/lib/municipitaly/province.rb +31 -0
- data/lib/municipitaly/region.rb +34 -0
- data/lib/municipitaly/region_delegator.rb +15 -0
- data/lib/municipitaly/search.rb +204 -0
- data/lib/municipitaly/version.rb +6 -0
- data/lib/municipitaly/zone.rb +38 -0
- data/lib/municipitaly/zone_delegator.rb +14 -0
- data/lib/municipitaly.rb +20 -0
- data/municipitaly.gemspec +36 -0
- data/vendor/data/municipalities.csv +7915 -0
- data/vendor/data/provinces.csv +108 -0
- data/vendor/data/regions.csv +21 -0
- data/vendor/data/zones.csv +6 -0
- metadata +129 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3bd44f85892a6fa5dc71682ef37b0fac7cc69c72c3d68680d86e1032ff0ad6b2
|
4
|
+
data.tar.gz: c15283a9165bf95b82f5437c92e2d4b44542343263ad53e4851bba02dc572b9f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 50f2d6867d566d86df52e738f498d7712c7b568e18ac9dfe00b1e7853bd18e1f0b9440848b790b89aa95c268c8d85514a6a0a1820b029a229cdfd86e2741faf8
|
7
|
+
data.tar.gz: b1bdc4317696449c0aa11b64fcf4dcfab8f457c7c0ad13a1e9b9eb56ea8cec9f53851e833946d08f6a117dcfe5694ee8aeafbaeac6c2cf7ed3d95a8387c28969
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
Metrics/BlockLength:
|
2
|
+
Max: 50
|
3
|
+
Exclude:
|
4
|
+
- 'municipitaly.gemspec'
|
5
|
+
- 'lib/**/*.rb'
|
6
|
+
- 'spec/**/*.rb'
|
7
|
+
|
8
|
+
Metrics/ParameterLists:
|
9
|
+
Max: 10
|
10
|
+
|
11
|
+
Style/ClassVars:
|
12
|
+
Exclude:
|
13
|
+
- 'lib/municipitaly/data.rb'
|
14
|
+
|
15
|
+
Style/CommentedKeyword:
|
16
|
+
Exclude:
|
17
|
+
- 'lib/municipitaly/search.rb'
|
18
|
+
|
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -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
data/Gemfile.lock
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
municipitaly (0.0.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
ast (2.4.0)
|
10
|
+
diff-lcs (1.3)
|
11
|
+
jaro_winkler (1.5.4)
|
12
|
+
parallel (1.19.1)
|
13
|
+
parser (2.6.5.0)
|
14
|
+
ast (~> 2.4.0)
|
15
|
+
rainbow (3.0.0)
|
16
|
+
rake (13.0.1)
|
17
|
+
rspec (3.9.0)
|
18
|
+
rspec-core (~> 3.9.0)
|
19
|
+
rspec-expectations (~> 3.9.0)
|
20
|
+
rspec-mocks (~> 3.9.0)
|
21
|
+
rspec-core (3.9.0)
|
22
|
+
rspec-support (~> 3.9.0)
|
23
|
+
rspec-expectations (3.9.0)
|
24
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
25
|
+
rspec-support (~> 3.9.0)
|
26
|
+
rspec-mocks (3.9.0)
|
27
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
28
|
+
rspec-support (~> 3.9.0)
|
29
|
+
rspec-support (3.9.0)
|
30
|
+
rubocop (0.77.0)
|
31
|
+
jaro_winkler (~> 1.5.1)
|
32
|
+
parallel (~> 1.10)
|
33
|
+
parser (>= 2.6)
|
34
|
+
rainbow (>= 2.2.2, < 4.0)
|
35
|
+
ruby-progressbar (~> 1.7)
|
36
|
+
unicode-display_width (>= 1.4.0, < 1.7)
|
37
|
+
ruby-progressbar (1.10.1)
|
38
|
+
unicode-display_width (1.6.0)
|
39
|
+
|
40
|
+
PLATFORMS
|
41
|
+
ruby
|
42
|
+
|
43
|
+
DEPENDENCIES
|
44
|
+
bundler (~> 2.1.4)
|
45
|
+
municipitaly!
|
46
|
+
rake (~> 13.0.1)
|
47
|
+
rspec (~> 3.9)
|
48
|
+
rubocop (~> 0.77)
|
49
|
+
|
50
|
+
BUNDLED WITH
|
51
|
+
2.1.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 NatyDev
|
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,188 @@
|
|
1
|
+
|
2
|
+
# 🇮🇹 Municipitaly
|
3
|
+
|
4
|
+
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, ...).
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'municipitaly'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install municipitaly
|
21
|
+
|
22
|
+
## Scenic
|
23
|
+
|
24
|
+
These entities are present, subpoints are data attributes:
|
25
|
+
|
26
|
+
* **Zone** - NUTS 1 (it: *Zona/Ripartizione geografica*)
|
27
|
+
* name
|
28
|
+
* code (it: *codice zona*)
|
29
|
+
* **Region** - NUTS 2 (it: *Regione*)
|
30
|
+
* name
|
31
|
+
* ISTAT code (it: *codice istat*)
|
32
|
+
* **Province** - NUTS 3 (it: *Provincia*)
|
33
|
+
* name
|
34
|
+
* ISTAT code (it: *codice istat*)
|
35
|
+
* acronym (it: *sigla*)
|
36
|
+
* **Municipality** (it: *Comune*)
|
37
|
+
* name
|
38
|
+
* ISTAT code (it: *codice istat*)
|
39
|
+
* cadastrial code (it: *codice catastale*)
|
40
|
+
* postal code(s) (it: *codice/i postale/i*)
|
41
|
+
* population
|
42
|
+
|
43
|
+
|
44
|
+
## Usage and examples
|
45
|
+
|
46
|
+
|
47
|
+
The **Municipitaly::Search** is the principal class used to search entities.
|
48
|
+
Returned data are stored in 4 different types of entity models:
|
49
|
+
|
50
|
+
- **Municipitaly::Zone**
|
51
|
+
- **Municipitaly::Region**
|
52
|
+
- **Municipitaly::Province**
|
53
|
+
- **Municipitaly::Municipality**
|
54
|
+
|
55
|
+
Retrieve all zones (return an array of `Municipitaly::Zone` objects):
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
zones = Municipitaly::Zone.all
|
59
|
+
# => [#<Municipitaly::Zone:0x0000...]
|
60
|
+
```
|
61
|
+
pick a random zone:
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
zone = zones.sample
|
65
|
+
# => #<Municipitaly::Zone:0x00007fb8390b9f48 @name="Centro", @code="3">
|
66
|
+
```
|
67
|
+
retrive data zone:
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
zone.name
|
71
|
+
# => "Centro"
|
72
|
+
zone.code
|
73
|
+
# => "3"
|
74
|
+
```
|
75
|
+
|
76
|
+
all regions belongs to a zone (return an array of `Municipitaly::Region` objects):
|
77
|
+
|
78
|
+
```ruby
|
79
|
+
zone.regions
|
80
|
+
# => [#<Municipitaly::Region:0x00007fb83883c550...]
|
81
|
+
```
|
82
|
+
|
83
|
+
and so for other entities:
|
84
|
+
|
85
|
+
```ruby
|
86
|
+
zone.provinces
|
87
|
+
# => [#<Municipitaly::Province:0x00007fb83a1478...]
|
88
|
+
|
89
|
+
zone.municipalities
|
90
|
+
# => [#<Municipitaly::Municipality:0x00007fb83a...]
|
91
|
+
```
|
92
|
+
|
93
|
+
### 🔎 Search
|
94
|
+
|
95
|
+
**Municipitaly::Search** is the most useful and interesting class: with that you can search single or multiple entities by the name, code or other attributes.
|
96
|
+
|
97
|
+
Search municipalities **from its name**: is case insensitive and can be partial (it returns an Array):
|
98
|
+
|
99
|
+
```ruby
|
100
|
+
municipalities = Municipitaly::Search.municipalities_from_name('ricco')
|
101
|
+
# => [#<Municipitaly::Municipality:0x00007fb839184838 @province_istat="028", @name="Borgoricco", @partial_istat="013", @cadastrial_code="B031", @postal_codes=["35010"], @population=8478>]
|
102
|
+
|
103
|
+
municipality = municipalities.first
|
104
|
+
# => #<Municipitaly::Municipality:0x00007fb83918483..>
|
105
|
+
|
106
|
+
municipality.name
|
107
|
+
# => "Borgoricco"
|
108
|
+
|
109
|
+
municipality.postal_codes
|
110
|
+
# => ["35010"]
|
111
|
+
```
|
112
|
+
|
113
|
+
from an entity object is possible to retrieve other parent objects and its attributes:
|
114
|
+
|
115
|
+
```ruby
|
116
|
+
municipality.province_name
|
117
|
+
# => "Padova"
|
118
|
+
|
119
|
+
municipality.province_acronym
|
120
|
+
# => "PD"
|
121
|
+
|
122
|
+
municipality.province
|
123
|
+
# => #<Municipitaly::Province:0x00007fb83a12701...>
|
124
|
+
|
125
|
+
municipality.region_name
|
126
|
+
# => "Veneto"
|
127
|
+
|
128
|
+
municipality.region
|
129
|
+
# => #<Municipitaly::Region:0x00007fb83883cf28...>
|
130
|
+
|
131
|
+
municipality.zone
|
132
|
+
# => #<Municipitaly::Zone:0x00007fb8390bb938...>
|
133
|
+
```
|
134
|
+
|
135
|
+
or retrieve nested entities:
|
136
|
+
|
137
|
+
```ruby
|
138
|
+
padua = municipality.province
|
139
|
+
# => #<Municipitaly::Province:0x00007fb83a127010...>
|
140
|
+
|
141
|
+
padua.municipalities
|
142
|
+
# => [#<Municipitaly::Municipality:0x00007fb83915b730...]
|
143
|
+
```
|
144
|
+
|
145
|
+
Search municipalities **from a single postal code**:
|
146
|
+
|
147
|
+
```ruby
|
148
|
+
municipalities = Municipitaly::Search.municipalities_from_postal_code('50145')
|
149
|
+
# => [#<Municipitaly::Municipality:0x00007fb83a295938 @province_istat="048", @name="Firenze"...]
|
150
|
+
|
151
|
+
florence = municipalities.first
|
152
|
+
# => #<Municipitaly::Municipality:0x00007fb83a295938...>
|
153
|
+
|
154
|
+
florence.postal_codes
|
155
|
+
# => ["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"]
|
156
|
+
```
|
157
|
+
|
158
|
+
Complete list of available class and instance methods are documented inside code, is suggested to use `rdoc`, read at next point.
|
159
|
+
|
160
|
+
|
161
|
+
### 📖 Rdoc
|
162
|
+
|
163
|
+
Clone locally this repository and run
|
164
|
+
`bundle exec rdoc` to produce complete documentation inside your local directory.
|
165
|
+
|
166
|
+
## Contributing
|
167
|
+
|
168
|
+
Fells free to improve or suggest new features/ideas.
|
169
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/natydev/municipitaly. 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.
|
170
|
+
|
171
|
+
If you want to contribute keep these guidelines in mind:
|
172
|
+
|
173
|
+
* Despite is an Italy focused gem, I accept only PR, issues and messages **in English** lang.
|
174
|
+
* Code must be well formatted and **offences free**, use the provided `rubocop` gem.
|
175
|
+
* Use the same **coding conventions** as the rest of the project.
|
176
|
+
* Code must be **tested** (with rspec).
|
177
|
+
* Write code according to **SOLID** Principles.
|
178
|
+
|
179
|
+
Steps to submit your code:
|
180
|
+
|
181
|
+
1. Fork the repo.
|
182
|
+
2. Oper your feature/namespaced branch
|
183
|
+
3. Commit your code following Github guidelines.
|
184
|
+
4. Make a PR with an exhaustive description.
|
185
|
+
|
186
|
+
## License
|
187
|
+
|
188
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
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 'municipitaly'
|
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,59 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Municipitaly
|
4
|
+
# Define collection
|
5
|
+
class Data
|
6
|
+
@@zones = []
|
7
|
+
@@regions = []
|
8
|
+
@@provinces = []
|
9
|
+
@@municipalities = []
|
10
|
+
|
11
|
+
def zones
|
12
|
+
puts find_csv('zones.csv')
|
13
|
+
if @@zones.empty?
|
14
|
+
CSV.foreach(find_csv('zones.csv'), headers: true) do |row|
|
15
|
+
@@zones << Zone.new(name: row[0], code: row[1])
|
16
|
+
end
|
17
|
+
end
|
18
|
+
@@zones
|
19
|
+
end
|
20
|
+
|
21
|
+
def regions
|
22
|
+
if @@regions.empty?
|
23
|
+
CSV.foreach(find_csv('regions.csv'), headers: true) do |row|
|
24
|
+
@@regions << Region.new(zone_code: row[0], name: row[1],
|
25
|
+
istat: row[2])
|
26
|
+
end
|
27
|
+
end
|
28
|
+
@@regions
|
29
|
+
end
|
30
|
+
|
31
|
+
def provinces
|
32
|
+
if @@provinces.empty?
|
33
|
+
CSV.foreach(find_csv('provinces.csv'), headers: true) do |row|
|
34
|
+
@@provinces << Province.new(region_istat: row[0], name: row[1],
|
35
|
+
istat: row[2], acronym: row[3])
|
36
|
+
end
|
37
|
+
end
|
38
|
+
@@provinces
|
39
|
+
end
|
40
|
+
|
41
|
+
def municipalities
|
42
|
+
if @@municipalities.empty?
|
43
|
+
CSV.foreach(find_csv('municipalities.csv'), headers: true) do |row|
|
44
|
+
@@municipalities <<
|
45
|
+
Municipality.new(province_istat: row[0],
|
46
|
+
name: row[1], partial_istat: row[2],
|
47
|
+
cadastrial_code: row[3], postal_codes: row[4],
|
48
|
+
population: row[5])
|
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 Municipitaly
|
4
|
+
# shared module to use Municipitaly::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
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Municipitaly
|
4
|
+
# Define data structure for a Municipality
|
5
|
+
class Municipality
|
6
|
+
extend Forwardable
|
7
|
+
include DataCaller
|
8
|
+
include RegionDelegator
|
9
|
+
include ZoneDelegator
|
10
|
+
|
11
|
+
def initialize(province_istat:, name:, partial_istat:,
|
12
|
+
cadastrial_code:, postal_codes:, population:) # :nodoc:
|
13
|
+
@province_istat = province_istat
|
14
|
+
@name = name
|
15
|
+
@partial_istat = partial_istat
|
16
|
+
@cadastrial_code = cadastrial_code
|
17
|
+
@postal_codes = postal_codes.split(' ')
|
18
|
+
@population = population.to_i
|
19
|
+
end
|
20
|
+
|
21
|
+
# <b>istat code</b> relative to parent province (String)
|
22
|
+
attr_reader :province_istat
|
23
|
+
|
24
|
+
# <b>name</b> of municipality (String)
|
25
|
+
attr_reader :name
|
26
|
+
|
27
|
+
attr_reader :partial_istat # :nodoc:
|
28
|
+
|
29
|
+
# <b>cadastrial code</b> of municipality (String)
|
30
|
+
attr_reader :cadastrial_code
|
31
|
+
|
32
|
+
# an Array of one or more postal code (as String)
|
33
|
+
attr_reader :postal_codes
|
34
|
+
|
35
|
+
# total <b>population</b> of municipality (Integer)
|
36
|
+
attr_reader :population
|
37
|
+
|
38
|
+
def_delegator :province, :acronym, :province_acronym
|
39
|
+
def_delegator :province, :name, :province_name
|
40
|
+
def_delegator :province, :region_istat, :region_istat
|
41
|
+
|
42
|
+
# returns an array of all +Municipitaly::Municipality+ objects.
|
43
|
+
def self.all
|
44
|
+
data.municipalities
|
45
|
+
end
|
46
|
+
|
47
|
+
# returns <b>istat code</b> for current municipality.
|
48
|
+
def istat
|
49
|
+
province_istat + partial_istat
|
50
|
+
end
|
51
|
+
|
52
|
+
# returns +Municipitaly::Province+ object for current municipality.
|
53
|
+
def province
|
54
|
+
@province ||= Search.province_from_istat(province_istat)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Municipitaly
|
4
|
+
# Define data structure for a Province
|
5
|
+
class Province
|
6
|
+
extend Forwardable
|
7
|
+
include DataCaller
|
8
|
+
include RegionDelegator
|
9
|
+
include ZoneDelegator
|
10
|
+
|
11
|
+
def initialize(region_istat:, name:, istat:, acronym:)
|
12
|
+
@region_istat = region_istat
|
13
|
+
@name = name
|
14
|
+
@istat = istat
|
15
|
+
@acronym = acronym
|
16
|
+
end
|
17
|
+
|
18
|
+
attr_reader :region_istat, :name, :istat, :acronym
|
19
|
+
|
20
|
+
# returns an array of all +Municipitaly::Province+ objects.
|
21
|
+
def self.all
|
22
|
+
data.provinces
|
23
|
+
end
|
24
|
+
|
25
|
+
# returns an array of all +Municipitaly::Municipality+ objects belongs
|
26
|
+
# to current province.
|
27
|
+
def municipalities
|
28
|
+
@municipalities ||= Search.municipalities_from_province_istat(istat)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Municipitaly
|
4
|
+
# Define data structure for a Region
|
5
|
+
class Region
|
6
|
+
include DataCaller
|
7
|
+
include ZoneDelegator
|
8
|
+
|
9
|
+
def initialize(zone_code:, name:, istat:)
|
10
|
+
@zone_code = zone_code
|
11
|
+
@name = name
|
12
|
+
@istat = istat
|
13
|
+
end
|
14
|
+
|
15
|
+
attr_reader :zone_code, :name, :istat
|
16
|
+
|
17
|
+
# returns an array of all +Municipitaly::Region+ objects.
|
18
|
+
def self.all
|
19
|
+
data.regions
|
20
|
+
end
|
21
|
+
|
22
|
+
# returns an array of all +Municipitaly::Province+ objects belongs
|
23
|
+
# to current region.
|
24
|
+
def provinces
|
25
|
+
@provinces ||= Search.provinces_from_region_istat(istat)
|
26
|
+
end
|
27
|
+
|
28
|
+
# returns an array of all +Municipitaly::Municipality+ objects belongs
|
29
|
+
# to current region.
|
30
|
+
def municipalities
|
31
|
+
@municipalities ||= Search.municipalities_from_region_istat(istat)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Municipitaly
|
4
|
+
# shared module to delegate Region istance and its methods
|
5
|
+
module RegionDelegator
|
6
|
+
extend Forwardable
|
7
|
+
|
8
|
+
def_delegator :region, :name, :region_name
|
9
|
+
def_delegator :region, :zone_code, :zone_code
|
10
|
+
|
11
|
+
def region
|
12
|
+
@region ||= Search.region_from_istat(region_istat)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|