cfita 0.0.3 → 0.0.5
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/cfita.gemspec +1 -1
- data/lib/cfita/codice_fiscale.rb +17 -11
- 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: 79fb90478a1c2e761048d863091a60dff5ea118a48b68527ecc2df1fb849d05f
|
4
|
+
data.tar.gz: cb18f19a6a571135d0a7c60963524c5af2d8f1d144283c64892eb93d957b47f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 896d41364afed131d83b36d5de1a606cf5e635c4273486c6d9daf20f2e0f272b3577fcf9d6125827286f5be1c0d7463b5ec019b0aa4d53708865e49bff5eb2bb
|
7
|
+
data.tar.gz: 6fed50fdd92d079305eb28a5578bcc1f6d496fe8ad6805f2195e933c728f8684eeb32f0e98bfc4a7a171f72db403e79319ba3bcedfa6ee9594be285e6e48c52e
|
data/cfita.gemspec
CHANGED
data/lib/cfita/codice_fiscale.rb
CHANGED
@@ -10,16 +10,16 @@ module Cfita
|
|
10
10
|
:sex,
|
11
11
|
:birth_place,
|
12
12
|
:birth_date,
|
13
|
-
:data,
|
14
13
|
:errors
|
15
14
|
|
16
15
|
def self.ccat
|
17
16
|
@ccat ||= JSON.parse(open('ccat.json'))
|
18
17
|
end
|
19
18
|
|
20
|
-
def initialize(fiscal_code, birth_place: nil)
|
19
|
+
def initialize(fiscal_code, birth_place: nil, birth_date: nil)
|
21
20
|
@fiscal_code = fiscal_code.upcase.strip
|
22
|
-
@birth_place = birth_place
|
21
|
+
@birth_place = birth_place&.upcase
|
22
|
+
@birth_date = birth_date && (birth_date.is_a?(Date) ? birth_date : Date.parse(birth_date))
|
23
23
|
@data = {}
|
24
24
|
@errors = []
|
25
25
|
parse
|
@@ -66,12 +66,17 @@ module Cfita
|
|
66
66
|
def check_sex
|
67
67
|
case @fiscal_code[9]
|
68
68
|
when /[0-3LMNP]/
|
69
|
-
|
69
|
+
sex = 'M'
|
70
70
|
when /[4-7QRST]/
|
71
|
-
|
71
|
+
sex = 'F'
|
72
72
|
else
|
73
73
|
@errors << 'Cifra decina giorno di nascita errata'
|
74
74
|
end
|
75
|
+
if @sex
|
76
|
+
errors << 'Sesso errato' if @sex != sex
|
77
|
+
else
|
78
|
+
@sex = sex
|
79
|
+
end
|
75
80
|
end
|
76
81
|
|
77
82
|
def check_birth_place
|
@@ -108,19 +113,20 @@ module Cfita
|
|
108
113
|
@errors << 'Cifra decina giorno di nascita errata' if day > 71
|
109
114
|
return if @errors.any?
|
110
115
|
|
111
|
-
@data[:sex] = day > 40 ? 'F' : 'M'
|
112
|
-
|
113
116
|
month = MESI.index(@fiscal_code[8])
|
114
117
|
@errors << 'Mese errato' unless month
|
115
118
|
return if @errors.any?
|
116
119
|
|
117
|
-
|
118
|
-
Date.new(yy2yyyy(yy), month + 1, day % 40) rescue nil
|
120
|
+
date = Date.new(yy2yyyy(yy), month + 1, day % 40) rescue nil
|
119
121
|
|
120
|
-
@errors << 'Data di nascita errata' unless
|
122
|
+
@errors << 'Data di nascita errata' unless date
|
121
123
|
return if @errors.any?
|
122
124
|
|
123
|
-
|
125
|
+
if @birth_date
|
126
|
+
@errors << 'Data di nascita errata' if @birth_date != date
|
127
|
+
else
|
128
|
+
@birth_date = date
|
129
|
+
end
|
124
130
|
end
|
125
131
|
|
126
132
|
def yy2yyyy(yy)
|