codice-fiscale 0.0.8 → 0.0.9
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/LICENSE +17 -18
- data/README.md +17 -5
- data/lib/codice_fiscale.rb +2 -2
- data/lib/codice_fiscale/helpers.rb +11 -12
- data/lib/codice_fiscale/version.rb +1 -1
- data/spec/lib/codice_fiscale/fiscal_code_spec.rb +2 -2
- metadata +18 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2e072ece1130ef8f44d55c4cc5302a5f75e5a9e7
|
4
|
+
data.tar.gz: 0bf6f20346f36a33672630176c8da7bcc260320c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 552e467c8f707cbfac1204f653a2fcef45ab2e3bcdc40c52cc15aeeccbf0a20010da084922cd68befb0aaf59dc75d2f2f16a6fef5e3be07a2890da2e380ffacd
|
7
|
+
data.tar.gz: c97c3375af51451728abea74762ea1c87836be9a7dc9c488ca8374c297daea8cff02126aef9a6985f60fef610835ae3e496b00c7fb875da46dc360f209eeb9af
|
data/LICENSE
CHANGED
@@ -1,22 +1,21 @@
|
|
1
|
-
|
1
|
+
The MIT License (MIT)
|
2
2
|
|
3
|
-
|
3
|
+
Copyright (c) 2012 topac
|
4
4
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
the following conditions:
|
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:
|
12
11
|
|
13
|
-
The above copyright notice and this permission notice shall be
|
14
|
-
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
15
14
|
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
OF
|
22
|
-
|
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
CHANGED
@@ -11,9 +11,15 @@ gender, birthdate and the birthplace. Read more on [wikipedia](http://en.wikiped
|
|
11
11
|
```ruby
|
12
12
|
require 'codice_fiscale'
|
13
13
|
|
14
|
-
CodiceFiscale.calculate
|
15
|
-
|
16
|
-
|
14
|
+
CodiceFiscale.calculate(
|
15
|
+
:name => 'Mario',
|
16
|
+
:surname => 'Rossi',
|
17
|
+
:gender => :male,
|
18
|
+
:birthdate => Date.new(1987, 1, 1),
|
19
|
+
:province_code => 'LC',
|
20
|
+
:city_name => 'Abbadia Lariana'
|
21
|
+
)
|
22
|
+
#=> RSSMRA87A01A005V
|
17
23
|
```
|
18
24
|
|
19
25
|
## City codes (Codici catastali)
|
@@ -22,11 +28,17 @@ If a person was born outside Italy, only the italian name of the county is requi
|
|
22
28
|
For example, an italian citizen born in France:
|
23
29
|
|
24
30
|
```ruby
|
25
|
-
CodiceFiscale.calculate
|
31
|
+
CodiceFiscale.calculate(
|
32
|
+
:name => 'Mario',
|
33
|
+
:surname => 'Rossi',
|
34
|
+
:gender => :male,
|
35
|
+
:birthdate => Date.new(1987, 1, 1),
|
36
|
+
:country_name => 'Francia'
|
37
|
+
)
|
26
38
|
```
|
27
39
|
|
28
40
|
If a person was born in Italy you have to specify the *code* of the province and the *name* of the city. These informations are actually contained in an XLS
|
29
|
-
document downloaded from [
|
41
|
+
document downloaded from [istat.it](http://www.istat.it/it/archivio/6789), converted to CSV and shipped with this gem.
|
30
42
|
|
31
43
|
**But what if you have your own table with all those codes?**
|
32
44
|
|
data/lib/codice_fiscale.rb
CHANGED
@@ -18,7 +18,7 @@ module CodiceFiscale
|
|
18
18
|
|
19
19
|
def self.calculate params
|
20
20
|
citizen = ItalianCitizen.new params
|
21
|
-
raise ArgumentError.new(
|
21
|
+
raise ArgumentError.new(citizen.errors.full_messages.join(', ')) unless citizen.valid?
|
22
22
|
citizen.fiscal_code
|
23
23
|
end
|
24
|
-
end
|
24
|
+
end
|
@@ -1,22 +1,20 @@
|
|
1
1
|
module CodiceFiscale
|
2
2
|
module Helpers
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
selected_letters = letters_a.select { |letter| letters_b.include? letter }
|
7
|
-
selected_letters.join ''
|
3
|
+
|
4
|
+
def multiset_intersection array_a, array_b
|
5
|
+
array_a.select { |letter| array_b.include? letter }
|
8
6
|
end
|
9
7
|
|
10
8
|
def consonants string
|
11
|
-
|
9
|
+
multiset_intersection(string.chars, Alphabet.consonants).join
|
12
10
|
end
|
13
11
|
|
14
12
|
def first_three_consonants string
|
15
|
-
|
13
|
+
multiset_intersection(string.chars, Alphabet.consonants)[0..2].join
|
16
14
|
end
|
17
15
|
|
18
16
|
def first_three_vowels string
|
19
|
-
|
17
|
+
multiset_intersection(string.chars, Alphabet.vowels)[0..2].join
|
20
18
|
end
|
21
19
|
|
22
20
|
def truncate_and_right_pad_with_three_x string
|
@@ -24,10 +22,11 @@ module CodiceFiscale
|
|
24
22
|
end
|
25
23
|
|
26
24
|
def first_three_consonants_than_vowels string
|
27
|
-
string.upcase
|
28
|
-
code = first_three_consonants
|
29
|
-
code << first_three_vowels(
|
25
|
+
upcase_string = string.upcase
|
26
|
+
code = first_three_consonants upcase_string
|
27
|
+
code << first_three_vowels(upcase_string)
|
30
28
|
truncate_and_right_pad_with_three_x code
|
31
29
|
end
|
30
|
+
|
32
31
|
end
|
33
|
-
end
|
32
|
+
end
|
@@ -110,7 +110,7 @@ describe CodiceFiscale::FiscalCode do
|
|
110
110
|
end
|
111
111
|
|
112
112
|
context 'when codes are fetched using csv' do
|
113
|
-
before { CodiceFiscale::Codes.stub
|
113
|
+
before { CodiceFiscale::Codes.stub(:city).and_return('hello') }
|
114
114
|
|
115
115
|
it 'returns the city code' do
|
116
116
|
fiscal_code.birthplace_part.should == 'hello'
|
@@ -130,7 +130,7 @@ describe CodiceFiscale::FiscalCode do
|
|
130
130
|
end
|
131
131
|
|
132
132
|
context 'when codes are fetched using csv' do
|
133
|
-
before { CodiceFiscale::Codes.stub
|
133
|
+
before { CodiceFiscale::Codes.stub(:country).and_return('Middle-Earth') }
|
134
134
|
|
135
135
|
it 'returns the country code' do
|
136
136
|
fiscal_code.birthplace_part.should == 'Middle-Earth'
|
metadata
CHANGED
@@ -1,97 +1,97 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: codice-fiscale
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- topac
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-02-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: guard-rspec
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rb-fsevent
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - ~>
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: 0.9.1
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - ~>
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 0.9.1
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: growl
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: activesupport
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: activemodel
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- -
|
87
|
+
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '0'
|
90
90
|
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- -
|
94
|
+
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
description: Calculate the italian fiscal code
|
@@ -101,7 +101,7 @@ executables: []
|
|
101
101
|
extensions: []
|
102
102
|
extra_rdoc_files: []
|
103
103
|
files:
|
104
|
-
- .gitignore
|
104
|
+
- ".gitignore"
|
105
105
|
- Gemfile
|
106
106
|
- Guardfile
|
107
107
|
- LICENSE
|
@@ -136,17 +136,17 @@ require_paths:
|
|
136
136
|
- lib
|
137
137
|
required_ruby_version: !ruby/object:Gem::Requirement
|
138
138
|
requirements:
|
139
|
-
- -
|
139
|
+
- - ">="
|
140
140
|
- !ruby/object:Gem::Version
|
141
141
|
version: '0'
|
142
142
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
143
143
|
requirements:
|
144
|
-
- -
|
144
|
+
- - ">="
|
145
145
|
- !ruby/object:Gem::Version
|
146
146
|
version: '0'
|
147
147
|
requirements: []
|
148
148
|
rubyforge_project:
|
149
|
-
rubygems_version: 2.
|
149
|
+
rubygems_version: 2.6.12
|
150
150
|
signing_key:
|
151
151
|
specification_version: 4
|
152
152
|
summary: Calculate the italian fiscal code
|