cfita 0.0.7 → 0.3.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 +4 -4
- data/.gitignore +2 -0
- data/README.md +46 -1
- data/cfita.gemspec +3 -2
- data/lib/cfita.rb +2 -0
- data/lib/cfita/codice_fiscale.rb +58 -49
- data/lib/cfita/codici_catastali.rb +6 -2
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5cef58c59196f0191df63c18b9780dff69ae3ae5412af8b2fdabfba0eb426295
|
4
|
+
data.tar.gz: c7d0adf7e96974485cf665d49697122490dbd99b9c312315f310eda7ea41528e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4db0e12e84f59d1e60d39dbd4409dfa9ed243c2ef5d2a7d1c1b77574ff957a1f931e4cafc4bf40aa548c663bc02407b8f3bbcc05f7183d423b64dfa024739968
|
7
|
+
data.tar.gz: dd13a735a96de5d038d822effac798e0b577a80077fdb8bc66dbe15a59883437dd1ea7e98c25643fb1f95e71165af0ef368a5d9fa45219a44be9ea92359c6ba9
|
data/.gitignore
ADDED
data/README.md
CHANGED
@@ -2,8 +2,53 @@
|
|
2
2
|
|
3
3
|
Check italian fiscal code
|
4
4
|
|
5
|
+
Intentionally this gem does not claim to "calculate" the tax code, which can be issued by the tax authorities of the Italian Republic (Revenue Agency).
|
6
|
+
|
5
7
|
see:
|
6
8
|
https://www.agenziaentrate.gov.it/wps/content/Nsilib/Nsi/Schede/Istanze/Richiesta+TS_CF/Informazioni+codificazione+pf
|
7
9
|
|
10
|
+
The purpose that it intends to achieve is exclusively to check if the personal data of the subject are consistent with the tested code.
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
Add this line to your application's Gemfile:
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
gem 'cfita'
|
18
|
+
```
|
19
|
+
|
20
|
+
And then execute:
|
21
|
+
|
22
|
+
```shell
|
23
|
+
bundle
|
24
|
+
```
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
require 'cfita'
|
29
|
+
|
30
|
+
p Cfita::CodiceFiscale.new('AAABBB50A50F839X')
|
31
|
+
=> #<Cfita::CodiceFiscale:0x00007fa4efd09558 @fiscal_code="AAABBB50A50F839X", @birth_place=nil, @birth_date=nil, @name=nil, @surname=nil, @sex=nil, @errors=["Checksum errato"]>
|
32
|
+
|
33
|
+
p Cfita::CodiceFiscale(
|
34
|
+
'AAABBB50A50F839U',
|
35
|
+
birth_place: 'Roma',
|
36
|
+
birth_date: '19600530',
|
37
|
+
sex: 'M',
|
38
|
+
name: 'MARIO',
|
39
|
+
surname: 'Rossi'
|
40
|
+
)
|
41
|
+
=> #<Cfita::CodiceFiscale:0x00007fa4e75abf98 @fiscal_code="AAABBB50A50F839U", @birth_place="ROMA", @birth_date=Mon, 30 May 1960, @name="MARIO", @surname="ROSSI", @sex="M", @errors=["Il nome non corrisponde al codice 'MRA'", "Il cognome non corrisponde al codice 'RSS'", "Luogo di nascita ROMA non coerente, al codice catastale F839 corrisponde a NAPOLI", "Sesso errato"]>
|
42
|
+
|
43
|
+
```
|
44
|
+
|
45
|
+
## Contributing
|
46
|
+
|
47
|
+
1. Fork it ( https://github.com/stefsava/cfita/fork )
|
48
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
49
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
50
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
51
|
+
5. Create new Pull Request
|
52
|
+
|
53
|
+
##
|
8
54
|
|
9
|
-
today_year = 1965 ; (0..99).each {|year| p [year, [1800,1900,2000].map {|mill| today_year - (mill + year)}.reject{|x| x < 14 }.min ].flatten }
|
data/cfita.gemspec
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
require File.join(__dir__, "lib", "cfita")
|
2
3
|
|
3
4
|
Gem::Specification.new do |s|
|
4
5
|
s.required_ruby_version = '>= 2.4'
|
5
6
|
s.name = 'cfita'
|
6
|
-
s.version =
|
7
|
-
s.date = '
|
7
|
+
s.version = Cfita::VERSION
|
8
|
+
s.date = '2021-06-02'
|
8
9
|
s.summary = 'Italian fiscal code checker'
|
9
10
|
s.description = 'Controllo codici fiscali italiani'
|
10
11
|
s.authors = ['Stefano Savanelli']
|
data/lib/cfita.rb
CHANGED
data/lib/cfita/codice_fiscale.rb
CHANGED
@@ -43,8 +43,53 @@ module Cfita
|
|
43
43
|
errors.empty?
|
44
44
|
end
|
45
45
|
|
46
|
+
def cf_sex
|
47
|
+
return @cf_sex if @cf_sex
|
48
|
+
case @fiscal_code[9]
|
49
|
+
when /[0-3LMNP]/
|
50
|
+
@cf_sex = 'M'
|
51
|
+
when /[4-7QRST]/
|
52
|
+
@cf_sex = 'F'
|
53
|
+
else
|
54
|
+
@errors << 'Cifra decina giorno di nascita errata'
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def cf_birth_places
|
59
|
+
return @cf_birth_places if @cf_birth_places
|
60
|
+
|
61
|
+
@cf_birth_places = CODICI_CATASTALI[codice_catastale]
|
62
|
+
end
|
63
|
+
|
64
|
+
def cf_birth_date
|
65
|
+
return @cf_birth_date if @cf_birth_date
|
66
|
+
yy = cifre(6..7)
|
67
|
+
day = cifre(9..10)
|
68
|
+
@errors << 'Cifra decina giorno di nascita errata' if day && day > 71
|
69
|
+
|
70
|
+
month = MESI.index(@fiscal_code[8])
|
71
|
+
@errors << 'Mese errato' unless month
|
72
|
+
return unless yy && month && day
|
73
|
+
|
74
|
+
@cf_birth_date = Date.new(yy2yyyy(yy), month + 1, day % 40) rescue nil
|
75
|
+
end
|
76
|
+
|
46
77
|
private
|
47
78
|
|
79
|
+
def codice_catastale
|
80
|
+
return @codice_catastale if @codice_catastale
|
81
|
+
letter = @fiscal_code[11]
|
82
|
+
numbers =
|
83
|
+
@fiscal_code[12..14]
|
84
|
+
.split(//)
|
85
|
+
.map do |c|
|
86
|
+
i = OMOCODICI.index(c)
|
87
|
+
i ? i.to_s : c
|
88
|
+
end
|
89
|
+
.join
|
90
|
+
letter + numbers
|
91
|
+
end
|
92
|
+
|
48
93
|
def parse
|
49
94
|
check_size
|
50
95
|
check_chars
|
@@ -111,76 +156,40 @@ module Cfita
|
|
111
156
|
end
|
112
157
|
|
113
158
|
def check_sex
|
114
|
-
case @fiscal_code[9]
|
115
|
-
when /[0-3LMNP]/
|
116
|
-
sex = 'M'
|
117
|
-
when /[4-7QRST]/
|
118
|
-
sex = 'F'
|
119
|
-
else
|
120
|
-
@errors << 'Cifra decina giorno di nascita errata'
|
121
|
-
end
|
122
159
|
if @sex
|
123
|
-
errors << 'Sesso errato' if @sex !=
|
160
|
+
errors << 'Sesso errato' if @sex != cf_sex
|
124
161
|
else
|
125
|
-
@sex =
|
162
|
+
@sex = cf_sex
|
126
163
|
end
|
127
164
|
end
|
128
165
|
|
129
166
|
def check_birth_place
|
130
|
-
#
|
131
|
-
letter = @fiscal_code[11]
|
132
|
-
numbers =
|
133
|
-
@fiscal_code[12..14]
|
134
|
-
.split(//)
|
135
|
-
.map do |c|
|
136
|
-
i = OMOCODICI.index(c)
|
137
|
-
i ? i.to_s : c
|
138
|
-
end
|
139
|
-
.join
|
140
|
-
codice_catastale = letter + numbers
|
141
|
-
|
142
|
-
birth_places = CODICI_CATASTALI[codice_catastale]
|
143
|
-
@errors << "Codice istat #{codice_catastale} non trovato" unless birth_places
|
167
|
+
@errors << "Codice istat #{codice_catastale} non trovato" unless cf_birth_places
|
144
168
|
if @birth_place
|
145
|
-
unless
|
146
|
-
@errors << "Luogo di nascita #{@birth_place} non coerente, al codice catastale #{codice_catastale} corrisponde a #{
|
169
|
+
unless cf_birth_places&.include?(@birth_place)
|
170
|
+
@errors << "Luogo di nascita #{@birth_place} non coerente, al codice catastale #{codice_catastale} corrisponde a #{cf_birth_places.join(' o a ')}"
|
147
171
|
end
|
148
172
|
end
|
149
173
|
end
|
150
174
|
|
151
175
|
MESI = 'ABCDEHLMPRST'
|
152
176
|
|
153
|
-
def
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
day = cifre(9..10)
|
158
|
-
return if @errors.any?
|
159
|
-
|
160
|
-
@errors << 'Cifra decina giorno di nascita errata' if day > 71
|
161
|
-
return if @errors.any?
|
162
|
-
|
163
|
-
month = MESI.index(@fiscal_code[8])
|
164
|
-
@errors << 'Mese errato' unless month
|
165
|
-
return if @errors.any?
|
166
|
-
|
167
|
-
date = Date.new(yy2yyyy(yy), month + 1, day % 40) rescue nil
|
177
|
+
def yy2yyyy(year_as_yy)
|
178
|
+
Date.today.year -
|
179
|
+
(Date.today.year % 100 + 100 - year_as_yy) % 100
|
180
|
+
end
|
168
181
|
|
169
|
-
|
182
|
+
def check_birth_date
|
183
|
+
@errors << 'Data di nascita errata' unless cf_birth_date
|
170
184
|
return if @errors.any?
|
171
185
|
|
172
186
|
if @birth_date
|
173
|
-
@errors << 'Data di nascita errata' if @birth_date !=
|
187
|
+
@errors << 'Data di nascita errata' if @birth_date != cf_birth_date
|
174
188
|
else
|
175
|
-
@birth_date =
|
189
|
+
@birth_date = cf_birth_date
|
176
190
|
end
|
177
191
|
end
|
178
192
|
|
179
|
-
def yy2yyyy(year_as_yy)
|
180
|
-
Date.today.year -
|
181
|
-
(Date.today.year % 100 + 100 - year_as_yy) % 100
|
182
|
-
end
|
183
|
-
|
184
193
|
def cifre(range)
|
185
194
|
result = 0
|
186
195
|
range.each do |position|
|
@@ -10412,6 +10412,10 @@ module Cfita
|
|
10412
10412
|
'M426' => ["COLCERESA"],
|
10413
10413
|
'M427' => ["LUSIANA CONCO"],
|
10414
10414
|
'M428' => ["PRESICCE-ACQUARICA"],
|
10415
|
+
'M429' => ["BORGO D'ANAUNIA"],
|
10416
|
+
'M430' => ["NOVELLA"],
|
10417
|
+
'M431' => ["VILLE DI FIEMME"],
|
10418
|
+
'M432' => ["MISILISCEMI"],
|
10415
10419
|
'Z100' => ["ALBANIA"],
|
10416
10420
|
'Z101' => ["ANDORRA"],
|
10417
10421
|
'Z102' => ["AUSTRIA"],
|
@@ -10464,7 +10468,7 @@ module Cfita
|
|
10464
10468
|
'Z149' => ["CROAZIA"],
|
10465
10469
|
'Z150' => ["SLOVENIA"],
|
10466
10470
|
'Z151' => ["TURKMENISTAN"],
|
10467
|
-
'Z152' => ["
|
10471
|
+
'Z152' => ["KAZAKISTAN"],
|
10468
10472
|
'Z153' => ["BOSNIA ED ERZEGOVINA"],
|
10469
10473
|
'Z154' => ["RUSSIA", "FEDERAZIONE RUSSA", "RUSSIA (FEDERAZIONE RUSSA)"],
|
10470
10474
|
'Z155' => ["SLOVACCHIA"],
|
@@ -10529,7 +10533,7 @@ module Cfita
|
|
10529
10533
|
'Z252' => ["ARMENIA"],
|
10530
10534
|
'Z253' => ["AZERBAIGIAN"],
|
10531
10535
|
'Z254' => ["GEORGIA"],
|
10532
|
-
'Z255' => ["
|
10536
|
+
'Z255' => ["KAZAKISTAN"],
|
10533
10537
|
'Z256' => ["KIRGHIZISTAN"],
|
10534
10538
|
'Z257' => ["TAGIKISTAN"],
|
10535
10539
|
'Z258' => ["TURKMENISTAN"],
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cfita
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stefano Savanelli
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-06-02 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Controllo codici fiscali italiani
|
14
14
|
email: stefano@savanelli.it
|
@@ -16,6 +16,7 @@ executables: []
|
|
16
16
|
extensions: []
|
17
17
|
extra_rdoc_files: []
|
18
18
|
files:
|
19
|
+
- ".gitignore"
|
19
20
|
- ".rubocop.yml"
|
20
21
|
- Gemfile
|
21
22
|
- README.md
|
@@ -28,7 +29,7 @@ homepage: https://rubygems.org/gems/cfita
|
|
28
29
|
licenses:
|
29
30
|
- MIT
|
30
31
|
metadata: {}
|
31
|
-
post_install_message:
|
32
|
+
post_install_message:
|
32
33
|
rdoc_options: []
|
33
34
|
require_paths:
|
34
35
|
- lib
|
@@ -43,8 +44,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
43
44
|
- !ruby/object:Gem::Version
|
44
45
|
version: '0'
|
45
46
|
requirements: []
|
46
|
-
rubygems_version: 3.
|
47
|
-
signing_key:
|
47
|
+
rubygems_version: 3.2.15
|
48
|
+
signing_key:
|
48
49
|
specification_version: 4
|
49
50
|
summary: Italian fiscal code checker
|
50
51
|
test_files:
|