itax_code 0.3.0 → 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 +4 -4
- data/.github/workflows/lint.yml +1 -1
- data/.github/workflows/release.yml +4 -0
- data/.github/workflows/test.yml +1 -1
- data/.rubocop.yml +1 -3
- data/CHANGELOG.md +12 -0
- data/Gemfile +2 -0
- data/Rakefile +2 -0
- data/bin/console +1 -0
- data/itax_code.gemspec +3 -0
- data/lib/itax_code/encoder.rb +3 -3
- data/lib/itax_code/omocode.rb +23 -12
- data/lib/itax_code/parser.rb +3 -1
- data/lib/itax_code/utils.rb +17 -17
- data/lib/itax_code/validator.rb +2 -0
- data/lib/itax_code/version.rb +3 -1
- data/lib/itax_code.rb +2 -0
- data/rakelib/cities.rake +3 -3
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ef915bc679fc9d2e15a5935b64e4c31cab6b638d0dc077d25f1f3ba7ab2859ef
|
4
|
+
data.tar.gz: 5c4ad64f192cae5530e5a434984539b9f5c0e27ad771d4bbd461118151ba5472
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0f80f432773b74fe19d74312c249279204681f211ab73bdaf60bde1c4a4fac1eace749a2bfaae75a38cf692e08b42f88723d27de9e9b29da81580980e9a79039
|
7
|
+
data.tar.gz: c0758b8d0fc862dd67e5a50842c17723368cbcc7a9e987c3e9d2683e992f55fb346cc6bc2e87374069304f247d1d0e24917c5eb0eee8b9d67b665444f79c0984
|
data/.github/workflows/lint.yml
CHANGED
data/.github/workflows/test.yml
CHANGED
data/.rubocop.yml
CHANGED
@@ -5,6 +5,7 @@ require:
|
|
5
5
|
- rubocop-rake
|
6
6
|
|
7
7
|
AllCops:
|
8
|
+
NewCops: enable
|
8
9
|
TargetRubyVersion: 2.5
|
9
10
|
|
10
11
|
Bundler/OrderedGems:
|
@@ -42,9 +43,6 @@ Metrics/MethodLength:
|
|
42
43
|
Style/Documentation:
|
43
44
|
Enabled: false
|
44
45
|
|
45
|
-
Style/FrozenStringLiteralComment:
|
46
|
-
Enabled: false
|
47
|
-
|
48
46
|
Style/StringLiterals:
|
49
47
|
Enabled: true
|
50
48
|
EnforcedStyle: double_quotes
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## [0.4.0](https://github.com/matteoredz/itax-code/compare/v0.3.0...v0.4.0) (2023-08-08)
|
4
|
+
|
5
|
+
|
6
|
+
### Features
|
7
|
+
|
8
|
+
* improve omocodes algo ([0834c43](https://github.com/matteoredz/itax-code/commit/0834c4372d300e29057bc283556b6af532cca722))
|
9
|
+
|
10
|
+
|
11
|
+
### Bug Fixes
|
12
|
+
|
13
|
+
* explicit the workflow permissions ([#17](https://github.com/matteoredz/itax-code/issues/17)) ([41d3515](https://github.com/matteoredz/itax-code/commit/41d35154db7f18622369a0b35ce0eb6b13fe4812))
|
14
|
+
|
3
15
|
## [0.3.0](https://github.com/matteoredz/itax-code/compare/v0.2.0...v0.3.0) (2023-06-30)
|
4
16
|
|
5
17
|
|
data/Gemfile
CHANGED
data/Rakefile
CHANGED
data/bin/console
CHANGED
data/itax_code.gemspec
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative "lib/itax_code/version"
|
2
4
|
|
3
5
|
Gem::Specification.new do |spec|
|
@@ -23,4 +25,5 @@ Gem::Specification.new do |spec|
|
|
23
25
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
26
|
spec.require_paths = ["lib"]
|
25
27
|
spec.add_dependency "activesupport"
|
28
|
+
spec.metadata["rubygems_mfa_required"] = "true"
|
26
29
|
end
|
data/lib/itax_code/encoder.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ItaxCode
|
2
4
|
# Handles the tax code generation logic.
|
3
5
|
#
|
@@ -60,9 +62,7 @@ module ItaxCode
|
|
60
62
|
consonants = utils.extract_consonants chars
|
61
63
|
vowels = utils.extract_vowels chars
|
62
64
|
|
63
|
-
if consonants.length > 3
|
64
|
-
consonants = consonants.chars.values_at(0, 2..consonants.chars.size).join
|
65
|
-
end
|
65
|
+
consonants = consonants.chars.values_at(0, 2..consonants.size).join if consonants.length > 3
|
66
66
|
|
67
67
|
"#{consonants[0..2]}#{vowels[0..2]}XXX"[0..2].upcase
|
68
68
|
end
|
data/lib/itax_code/omocode.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ItaxCode
|
2
4
|
class Omocode
|
3
5
|
attr_reader :tax_code, :utils
|
@@ -11,26 +13,35 @@ module ItaxCode
|
|
11
13
|
@utils = utils
|
12
14
|
end
|
13
15
|
|
14
|
-
# Computes the omocodes from a given tax_code
|
16
|
+
# Computes the omocodes from a given tax_code by first identifying the original
|
17
|
+
# tax_code and then appending all the omocodes.
|
15
18
|
#
|
16
19
|
# @return [Array]
|
17
|
-
def
|
18
|
-
|
19
|
-
|
20
|
+
def omocodes
|
21
|
+
[original_omocode] + utils.omocodia_indexes_combos.map do |combo|
|
22
|
+
omocode(combo, ->(char) { utils.omocodia_encode(char) })
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# The original omocode is the one that have all the omocody indexes decoded
|
27
|
+
# as number, and from which any of its omocodes are generated.
|
28
|
+
#
|
29
|
+
# @return [String]
|
30
|
+
def original_omocode
|
31
|
+
omocode(utils.omocodia_indexes, ->(char) { utils.omocodia_decode(char) })
|
20
32
|
end
|
21
33
|
|
22
34
|
private
|
23
35
|
|
24
|
-
def
|
25
|
-
|
26
|
-
|
27
|
-
|
36
|
+
def omocode(indexes, translation)
|
37
|
+
chars = tax_code[0..14].chars
|
38
|
+
|
39
|
+
indexes.each do |index|
|
40
|
+
chars[index] = translation.call(chars[index])
|
28
41
|
end
|
29
|
-
end
|
30
42
|
|
31
|
-
|
32
|
-
|
33
|
-
code + utils.encode_cin(code)
|
43
|
+
omocode = chars.join
|
44
|
+
omocode + utils.encode_cin(omocode)
|
34
45
|
end
|
35
46
|
end
|
36
47
|
end
|
data/lib/itax_code/parser.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "itax_code/omocode"
|
2
4
|
|
3
5
|
module ItaxCode
|
@@ -30,7 +32,7 @@ module ItaxCode
|
|
30
32
|
gender: gender,
|
31
33
|
birthdate: birthdate,
|
32
34
|
birthplace: birthplace,
|
33
|
-
omocodes: Omocode.new(tax_code).
|
35
|
+
omocodes: Omocode.new(tax_code).omocodes,
|
34
36
|
raw: raw
|
35
37
|
}
|
36
38
|
end
|
data/lib/itax_code/utils.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "csv"
|
2
4
|
|
3
5
|
module ItaxCode
|
@@ -10,9 +12,7 @@ module ItaxCode
|
|
10
12
|
end
|
11
13
|
|
12
14
|
def slugged(str, separator = "-")
|
13
|
-
str.gsub
|
14
|
-
str.gsub!(/\s*&\s*/, " and ")
|
15
|
-
str.parameterize(separator: separator)
|
15
|
+
str.gsub(/\s*@\s*/, " at ").gsub(/\s*&\s*/, " and ").parameterize(separator: separator)
|
16
16
|
end
|
17
17
|
|
18
18
|
def months
|
@@ -29,23 +29,17 @@ module ItaxCode
|
|
29
29
|
|
30
30
|
def cin_odds
|
31
31
|
{
|
32
|
-
"0": 1,
|
33
|
-
|
34
|
-
|
35
|
-
"I": 19, "J": 21, "K": 2, "L": 4, "M": 18, "N": 20,
|
36
|
-
"O": 11, "P": 3, "Q": 6, "R": 8, "S": 12, "T": 14,
|
37
|
-
"U": 16, "V": 10, "W": 22, "X": 25, "Y": 24, "Z": 23
|
32
|
+
"0": 1, "1": 0, "2": 5, "3": 7, "4": 9, "5": 13, "6": 15, "7": 17, "8": 19, "9": 21,
|
33
|
+
A: 1, B: 0, C: 5, D: 7, E: 9, F: 13, G: 15, H: 17, I: 19, J: 21, K: 2, L: 4, M: 18,
|
34
|
+
N: 20, O: 11, P: 3, Q: 6, R: 8, S: 12, T: 14, U: 16, V: 10, W: 22, X: 25, Y: 24, Z: 23
|
38
35
|
}
|
39
36
|
end
|
40
37
|
|
41
38
|
def cin_evens
|
42
39
|
{
|
43
|
-
"0": 0,
|
44
|
-
|
45
|
-
|
46
|
-
"I": 8, "J": 9, "K": 10, "L": 11, "M": 12, "N": 13,
|
47
|
-
"O": 14, "P": 15, "Q": 16, "R": 17, "S": 18, "T": 19,
|
48
|
-
"U": 20, "V": 21, "W": 22, "X": 23, "Y": 24, "Z": 25
|
40
|
+
"0": 0, "1": 1, "2": 2, "3": 3, "4": 4, "5": 5, "6": 6, "7": 7, "8": 8, "9": 9,
|
41
|
+
A: 0, B: 1, C: 2, D: 3, E: 4, F: 5, G: 6, H: 7, I: 8, J: 9, K: 10, L: 11, M: 12, N: 13,
|
42
|
+
O: 14, P: 15, Q: 16, R: 17, S: 18, T: 19, U: 20, V: 21, W: 22, X: 23, Y: 24, Z: 25
|
49
43
|
}
|
50
44
|
end
|
51
45
|
|
@@ -68,8 +62,14 @@ module ItaxCode
|
|
68
62
|
omocodia.values.join
|
69
63
|
end
|
70
64
|
|
71
|
-
def
|
72
|
-
[6, 7, 9, 10, 12, 13, 14]
|
65
|
+
def omocodia_indexes
|
66
|
+
[6, 7, 9, 10, 12, 13, 14].reverse
|
67
|
+
end
|
68
|
+
|
69
|
+
def omocodia_indexes_combos
|
70
|
+
(1..omocodia_indexes.size).flat_map do |index|
|
71
|
+
omocodia_indexes.combination(index).to_a
|
72
|
+
end
|
73
73
|
end
|
74
74
|
|
75
75
|
def omocodia_encode(val)
|
data/lib/itax_code/validator.rb
CHANGED
data/lib/itax_code/version.rb
CHANGED
data/lib/itax_code.rb
CHANGED
data/rakelib/cities.rake
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "csv"
|
2
4
|
require "net/http"
|
3
5
|
require "tempfile"
|
@@ -25,9 +27,7 @@ namespace :cities do
|
|
25
27
|
end
|
26
28
|
end
|
27
29
|
|
28
|
-
File.
|
29
|
-
output_file.write(output_string)
|
30
|
-
end
|
30
|
+
File.write("lib/itax_code/data/cities.csv", output_string)
|
31
31
|
ensure
|
32
32
|
tempfile.close
|
33
33
|
tempfile.unlink
|
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.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matteo Rossi
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-08-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -24,7 +24,7 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
-
description:
|
27
|
+
description:
|
28
28
|
email:
|
29
29
|
- mttrss5@gmail.com
|
30
30
|
executables: []
|
@@ -64,7 +64,8 @@ metadata:
|
|
64
64
|
homepage_uri: https://github.com/matteoredz/itax-code
|
65
65
|
source_code_uri: https://github.com/matteoredz/itax-code
|
66
66
|
changelog_uri: https://github.com/matteoredz/itax-code/CHANGELOG.md
|
67
|
-
|
67
|
+
rubygems_mfa_required: 'true'
|
68
|
+
post_install_message:
|
68
69
|
rdoc_options: []
|
69
70
|
require_paths:
|
70
71
|
- lib
|
@@ -79,8 +80,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
79
80
|
- !ruby/object:Gem::Version
|
80
81
|
version: '0'
|
81
82
|
requirements: []
|
82
|
-
rubygems_version: 3.
|
83
|
-
signing_key:
|
83
|
+
rubygems_version: 3.4.10
|
84
|
+
signing_key:
|
84
85
|
specification_version: 4
|
85
86
|
summary: Encode and decode Italian tax code (Codice Fiscale)
|
86
87
|
test_files: []
|