itax_code 0.1.4 → 0.2.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/Gemfile.lock +6 -6
- data/README.md +5 -5
- data/lib/itax_code/encoder.rb +26 -14
- data/lib/itax_code/parser.rb +1 -1
- data/lib/itax_code/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 15fec89c684546176ef2c266a3c2b896225ba46b3051798bda0fca1975f03f89
|
4
|
+
data.tar.gz: bc02a9d22d009daf6800cc616d1ce84827267eaa877bc6e7b591c0707b3eee08
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5121195f517531b125f1b8cb94c8c45b071b557068d4875e67ab87b5425d57fd4c73374d3c833885c5d66da43cae1cd0d27c2598a420aa4c0e8b83cb0e91b92e
|
7
|
+
data.tar.gz: 3805ae947b4505220130467207f5d86808825722bc3c563021cd163986a8643c996e9bdf1c01fa9918c2e111868f7a2204508a3d9c299e50c195333a7668411a
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
itax_code (0.
|
4
|
+
itax_code (0.2.0)
|
5
5
|
activesupport
|
6
6
|
|
7
7
|
GEM
|
@@ -22,13 +22,13 @@ GEM
|
|
22
22
|
minitest (5.14.4)
|
23
23
|
mocha (1.13.0)
|
24
24
|
parallel (1.21.0)
|
25
|
-
parser (3.0.
|
25
|
+
parser (3.0.3.0)
|
26
26
|
ast (~> 2.4.1)
|
27
27
|
rainbow (3.0.0)
|
28
28
|
rake (13.0.6)
|
29
29
|
regexp_parser (2.1.1)
|
30
30
|
rexml (3.2.5)
|
31
|
-
rubocop (1.
|
31
|
+
rubocop (1.23.0)
|
32
32
|
parallel (~> 1.10)
|
33
33
|
parser (>= 3.0.0.0)
|
34
34
|
rainbow (>= 2.2.2, < 4.0)
|
@@ -37,9 +37,9 @@ GEM
|
|
37
37
|
rubocop-ast (>= 1.12.0, < 2.0)
|
38
38
|
ruby-progressbar (~> 1.7)
|
39
39
|
unicode-display_width (>= 1.4.0, < 3.0)
|
40
|
-
rubocop-ast (1.
|
40
|
+
rubocop-ast (1.13.0)
|
41
41
|
parser (>= 3.0.1.1)
|
42
|
-
rubocop-minitest (0.
|
42
|
+
rubocop-minitest (0.17.0)
|
43
43
|
rubocop (>= 0.90, < 2.0)
|
44
44
|
rubocop-performance (1.12.0)
|
45
45
|
rubocop (>= 1.7.0, < 2.0)
|
@@ -71,4 +71,4 @@ DEPENDENCIES
|
|
71
71
|
simplecov
|
72
72
|
|
73
73
|
BUNDLED WITH
|
74
|
-
2.
|
74
|
+
2.2.28
|
data/README.md
CHANGED
@@ -29,9 +29,9 @@ Or install it yourself as:
|
|
29
29
|
ItaxCode.encode(
|
30
30
|
surname: "Rossi",
|
31
31
|
name: "Mario",
|
32
|
-
gender: "M", #
|
33
|
-
birthdate: "1980-
|
34
|
-
birthplace: "Milano"
|
32
|
+
gender: "M", # M|F
|
33
|
+
birthdate: "1980-01-01", # String|Time|Date|DateTime
|
34
|
+
birthplace: "Milano" # Name(Milano)|code(F205)
|
35
35
|
)
|
36
36
|
```
|
37
37
|
|
@@ -45,7 +45,7 @@ ItaxCode.decode("RSSMRA80A01F205X")
|
|
45
45
|
# {
|
46
46
|
# code: "RSSMRA80A01F205X",
|
47
47
|
# gender: "M",
|
48
|
-
# birthdate: "1980-
|
48
|
+
# birthdate: "1980-01-01",
|
49
49
|
# birthplace: {
|
50
50
|
# code: "F205",
|
51
51
|
# province: "MI",
|
@@ -83,7 +83,7 @@ ItaxCode.valid?(
|
|
83
83
|
surname: "Rossi",
|
84
84
|
name: "Mario",
|
85
85
|
gender: "M",
|
86
|
-
birthdate: "1980-
|
86
|
+
birthdate: "1980-01-01",
|
87
87
|
birthplace: "Milano"
|
88
88
|
}
|
89
89
|
)
|
data/lib/itax_code/encoder.rb
CHANGED
@@ -10,9 +10,9 @@ module ItaxCode
|
|
10
10
|
# @example
|
11
11
|
# ItaxCode::Encoder.new(
|
12
12
|
# surname: "Rossi",
|
13
|
-
# name: "
|
13
|
+
# name: "Mario",
|
14
14
|
# gender: "M",
|
15
|
-
# birthdate: "
|
15
|
+
# birthdate: "1980-01-01",
|
16
16
|
# birthplace: "Milano"
|
17
17
|
# ).encode
|
18
18
|
#
|
@@ -24,15 +24,12 @@ module ItaxCode
|
|
24
24
|
@surname = data[:surname]
|
25
25
|
@name = data[:name]
|
26
26
|
@gender = data[:gender]&.upcase
|
27
|
-
@birthdate =
|
27
|
+
@birthdate = data[:birthdate].to_s
|
28
28
|
@birthplace = data[:birthplace]
|
29
29
|
@utils = utils
|
30
|
+
validate_data_presence!
|
30
31
|
|
31
|
-
|
32
|
-
next if instance_variable_get(ivar).present?
|
33
|
-
|
34
|
-
raise MissingDataError, "missing #{ivar} value"
|
35
|
-
end
|
32
|
+
@birthdate = parse_birthdate!
|
36
33
|
end
|
37
34
|
|
38
35
|
# Computes the tax code from its components.
|
@@ -78,15 +75,30 @@ module ItaxCode
|
|
78
75
|
"#{year}#{month}#{day}"
|
79
76
|
end
|
80
77
|
|
81
|
-
def encode_birthplace(src = utils.cities,
|
82
|
-
|
83
|
-
|
84
|
-
|
78
|
+
def encode_birthplace(src = utils.cities, stop: false)
|
79
|
+
lookup_key = birthplace.match?(/^\w{1}\d{3}$/) ? "code" : "name"
|
80
|
+
place_slug = utils.slugged(birthplace)
|
81
|
+
place_item = src.find { |i| place_slug == utils.slugged(i[lookup_key]) }
|
85
82
|
|
86
|
-
code =
|
83
|
+
code = place_item.try(:[], "code")
|
87
84
|
return code if code.present?
|
85
|
+
raise MissingDataError, "no code found for #{birthplace}" if stop
|
86
|
+
|
87
|
+
encode_birthplace(utils.countries, stop: true)
|
88
|
+
end
|
89
|
+
|
90
|
+
def validate_data_presence!
|
91
|
+
instance_variables.each do |ivar|
|
92
|
+
next if instance_variable_get(ivar).present?
|
93
|
+
|
94
|
+
raise MissingDataError, "missing #{ivar} value"
|
95
|
+
end
|
96
|
+
end
|
88
97
|
|
89
|
-
|
98
|
+
def parse_birthdate!
|
99
|
+
Date.parse(birthdate)
|
100
|
+
rescue StandardError
|
101
|
+
raise ArgumentError, "#{birthdate} is not a valid date"
|
90
102
|
end
|
91
103
|
end
|
92
104
|
end
|
data/lib/itax_code/parser.rb
CHANGED
data/lib/itax_code/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: itax_code
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matteo Rossi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-11-
|
11
|
+
date: 2021-11-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|