cfita 0.3.1 → 0.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 424b84e97b24a15273e3ef1cfc4cf7af8d333342acde10d656375f9e97eec6f9
4
- data.tar.gz: 401e7387c2e19cafea5ef406f33ed30ab4dac68147fcaa6162038f93cca82703
3
+ metadata.gz: b0510a1eea1c9a417a70c0d5fbb91a275495569963e745dea6d369df11f91e32
4
+ data.tar.gz: a0d7f593151788aab9617dbc9922778d214b29e73784734a76874925188ce937
5
5
  SHA512:
6
- metadata.gz: 293c36acf2d95209ca2e6602b9052087b20f4a45a073c541e0a6042d113475ce7b988e3961fb2d73a46d5d7bc468f06307df54ed000ed2db275acae59c87ff2d
7
- data.tar.gz: 5962972ecfbffdea99f53423c480b3ff962e205b15a90d4d47cf9c73c79af2b4ceb103ef108dd13f151be6b61f8827ea7c1ac59e199e06202af8315a701744a7
6
+ metadata.gz: 69ef59d65dbc4403b74a74da2d848682277855d862e30056201bc24f1c0f4c49ccba60f2396ce30cdaa4396201c04930a3ef4cd165e38cc08844b6509c948cc8
7
+ data.tar.gz: fe5325bdf5a020c0da7d0f1832261da154ec8a48e926c33b97ae261a03e28c448eed62a07069c3b17d413324c3f4d83bdfa631475aee1e05786992748b406d36
data/.gitignore CHANGED
@@ -1,2 +1,3 @@
1
1
  *.gem
2
- test/cfs.txt
2
+ test/cfs.txt
3
+ Gemfile.lock
data/CHANGELOG.md CHANGED
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## v0.4.0 - 2022-12-10
9
+
10
+ ### Fix
11
+
12
+ - return nil from cf_sex, cf_birth_places and cf_birth_date when fiscal code is invalid
13
+
8
14
  ## v0.3.1 - 2022-12-10
9
15
 
10
16
  ### Added
@@ -46,12 +46,14 @@ module Cfita
46
46
  def cf_sex
47
47
  return @cf_sex if @cf_sex
48
48
  case @fiscal_code[9]
49
+ when nil
49
50
  when /[0-3LMNP]/
50
51
  @cf_sex = 'M'
51
52
  when /[4-7QRST]/
52
53
  @cf_sex = 'F'
53
54
  else
54
55
  @errors << 'Cifra decina giorno di nascita errata'
56
+ nil
55
57
  end
56
58
  end
57
59
 
@@ -63,10 +65,12 @@ module Cfita
63
65
 
64
66
  def cf_birth_date
65
67
  return @cf_birth_date if @cf_birth_date
68
+
66
69
  yy = cifre(6..7)
67
70
  day = cifre(9..10)
71
+ return unless yy && day
68
72
  @errors << 'Cifra decina giorno di nascita errata' if day && day > 71
69
-
73
+
70
74
  month = MESI.index(@fiscal_code[8])
71
75
  @errors << 'Mese errato' unless month
72
76
  return unless yy && month && day
@@ -76,17 +80,15 @@ module Cfita
76
80
 
77
81
  private
78
82
 
79
- def codice_catastale
83
+ def codice_catastale
80
84
  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
85
+ return unless letter = @fiscal_code[11]
86
+ return unless numbers = @fiscal_code[12..14]
87
+
88
+ numbers = numbers.chars.map do |c|
89
+ i = OMOCODICI.index(c)
90
+ i ? i.to_s : c
91
+ end.join
90
92
  letter + numbers
91
93
  end
92
94
 
@@ -194,6 +196,8 @@ module Cfita
194
196
  result = 0
195
197
  range.each do |position|
196
198
  char = @fiscal_code[position]
199
+ return nil unless char
200
+
197
201
  value = CIFRE.index(char)
198
202
  @errors << "Carattere '#{char}' errato in posizione #{position}" unless value
199
203
  return nil unless value
data/lib/cfita.rb CHANGED
@@ -4,5 +4,5 @@
4
4
  module Cfita
5
5
  require 'cfita/codice_fiscale'
6
6
 
7
- VERSION='0.3.1'
7
+ VERSION='0.4.0'
8
8
  end
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.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefano Savanelli