cfita 0.0.7 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +46 -1
- data/cfita.gemspec +1 -1
- data/lib/cfita/codice_fiscale.rb +59 -49
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cc1bb03b9e46198f95207407208091e50e7d110eb23985a8645134bcb3956fd5
|
4
|
+
data.tar.gz: ec40c4c49f8dac27a97de0c019529b3ec32b004f9b3cbc5139129a4952fa5d17
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 64ee2413b53ebbf3c2d11a8c67e344fa0f2fc60250b5c011ed04bfa644dafb704240dd52f922089996a4a7a2133f2d1f10b165b189b48eaef251d3dc1857c7d4
|
7
|
+
data.tar.gz: bd5002cce1852d00099d06f1c8f79097e9d2b2b1cdd67ee30efd06f17d1332c4805ed4c17b8576f29f02b4a23a60ea39d347a26f33ea7b4a51de3cc035d67a37
|
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
data/lib/cfita/codice_fiscale.rb
CHANGED
@@ -43,6 +43,52 @@ 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
|
+
letter = @fiscal_code[11]
|
62
|
+
numbers =
|
63
|
+
@fiscal_code[12..14]
|
64
|
+
.split(//)
|
65
|
+
.map do |c|
|
66
|
+
i = OMOCODICI.index(c)
|
67
|
+
i ? i.to_s : c
|
68
|
+
end
|
69
|
+
.join
|
70
|
+
codice_catastale = letter + numbers
|
71
|
+
@cf_birth_places = CODICI_CATASTALI[codice_catastale]
|
72
|
+
end
|
73
|
+
|
74
|
+
def cf_birth_date
|
75
|
+
return @cf_birth_date if @cf_birth_date
|
76
|
+
yy = cifre(6..7)
|
77
|
+
return if @errors.any?
|
78
|
+
|
79
|
+
day = cifre(9..10)
|
80
|
+
return if @errors.any?
|
81
|
+
|
82
|
+
@errors << 'Cifra decina giorno di nascita errata' if day > 71
|
83
|
+
return if @errors.any?
|
84
|
+
|
85
|
+
month = MESI.index(@fiscal_code[8])
|
86
|
+
@errors << 'Mese errato' unless month
|
87
|
+
return if @errors.any?
|
88
|
+
|
89
|
+
@cf_birth_date = Date.new(yy2yyyy(yy), month + 1, day % 40) rescue nil
|
90
|
+
end
|
91
|
+
|
46
92
|
private
|
47
93
|
|
48
94
|
def parse
|
@@ -111,76 +157,40 @@ module Cfita
|
|
111
157
|
end
|
112
158
|
|
113
159
|
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
160
|
if @sex
|
123
|
-
errors << 'Sesso errato' if @sex !=
|
161
|
+
errors << 'Sesso errato' if @sex != cf_sex
|
124
162
|
else
|
125
|
-
@sex =
|
163
|
+
@sex = cf_sex
|
126
164
|
end
|
127
165
|
end
|
128
166
|
|
129
167
|
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
|
168
|
+
@errors << "Codice istat #{codice_catastale} non trovato" unless cf_birth_places
|
144
169
|
if @birth_place
|
145
|
-
unless
|
146
|
-
@errors << "Luogo di nascita #{@birth_place} non coerente, al codice catastale #{codice_catastale} corrisponde a #{
|
170
|
+
unless cf_birth_places&.include?(@birth_place)
|
171
|
+
@errors << "Luogo di nascita #{@birth_place} non coerente, al codice catastale #{codice_catastale} corrisponde a #{cf_birth_places.join(' o a ')}"
|
147
172
|
end
|
148
173
|
end
|
149
174
|
end
|
150
175
|
|
151
176
|
MESI = 'ABCDEHLMPRST'
|
152
177
|
|
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
|
178
|
+
def yy2yyyy(year_as_yy)
|
179
|
+
Date.today.year -
|
180
|
+
(Date.today.year % 100 + 100 - year_as_yy) % 100
|
181
|
+
end
|
168
182
|
|
169
|
-
|
183
|
+
def check_birth_date
|
184
|
+
@errors << 'Data di nascita errata' unless cf_birth_date
|
170
185
|
return if @errors.any?
|
171
186
|
|
172
187
|
if @birth_date
|
173
|
-
@errors << 'Data di nascita errata' if @birth_date !=
|
188
|
+
@errors << 'Data di nascita errata' if @birth_date != cf_birth_date
|
174
189
|
else
|
175
|
-
@birth_date =
|
190
|
+
@birth_date = cf_birth_date
|
176
191
|
end
|
177
192
|
end
|
178
193
|
|
179
|
-
def yy2yyyy(year_as_yy)
|
180
|
-
Date.today.year -
|
181
|
-
(Date.today.year % 100 + 100 - year_as_yy) % 100
|
182
|
-
end
|
183
|
-
|
184
194
|
def cifre(range)
|
185
195
|
result = 0
|
186
196
|
range.each do |position|
|