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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cde208e3879aafdbbb4ea46d0bb5578eb7b99f187b583a4846a7518b11c2c6ea
4
- data.tar.gz: a2700a15447c8aafdd80244f58f8ed0b43f387232258f6e1f5042fb11a103611
3
+ metadata.gz: cc1bb03b9e46198f95207407208091e50e7d110eb23985a8645134bcb3956fd5
4
+ data.tar.gz: ec40c4c49f8dac27a97de0c019529b3ec32b004f9b3cbc5139129a4952fa5d17
5
5
  SHA512:
6
- metadata.gz: b709885f022101043cd727e3ffb381f44db7f271db8c63cdb9446008f71095fb50d37bfac022f1c71ee12b6f4b3390fc286befe0a0336022201d518048bff716
7
- data.tar.gz: f0bdf38ce0c94992661b68e7e0a3163a2f2ff2551c5f88f416e671c61dbd2206ad06a41924f499c031e1563351a19cacfb8e9dd47b970fce52a23316efa7e8ca
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 }
@@ -3,7 +3,7 @@
3
3
  Gem::Specification.new do |s|
4
4
  s.required_ruby_version = '>= 2.4'
5
5
  s.name = 'cfita'
6
- s.version = '0.0.7'
6
+ s.version = '0.1.1'
7
7
  s.date = '2019-06-18'
8
8
  s.summary = 'Italian fiscal code checker'
9
9
  s.description = 'Controllo codici fiscali italiani'
@@ -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 != sex
161
+ errors << 'Sesso errato' if @sex != cf_sex
124
162
  else
125
- @sex = sex
163
+ @sex = cf_sex
126
164
  end
127
165
  end
128
166
 
129
167
  def check_birth_place
130
- # debugger
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 birth_places&.include?(@birth_place)
146
- @errors << "Luogo di nascita #{@birth_place} non coerente, al codice catastale #{codice_catastale} corrisponde a #{birth_places.join(' o 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 check_birth_date
154
- yy = cifre(6..7)
155
- return if @errors.any?
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
- @errors << 'Data di nascita errata' unless date
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 != date
188
+ @errors << 'Data di nascita errata' if @birth_date != cf_birth_date
174
189
  else
175
- @birth_date = 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|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cfita
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefano Savanelli