itax_code 2.0.3 → 2.0.4

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: 6055ffa03056e37ff605e5273139c5cea2e996e8e1e0f05abf5756ddcb313387
4
- data.tar.gz: 5f7670f8a377c36470b2e9cd579aea1eedaaebc585b457ca3ca2bda4444d161e
3
+ metadata.gz: 28b67a1393b6940ab8824514b430ecfee7cb9a7eca1208b6f6656b25049d933b
4
+ data.tar.gz: 8d2b668cb365b5831cfa2c384ab3b1525fb50f289e7c470310bcb4c963d88217
5
5
  SHA512:
6
- metadata.gz: dc8016fd81f3524b133a66779db88cee832f7069debd04ddafd5cbcde0039ddaeee24726d1c7da6417be387cdef395eb0d0c739168ca03aaacd067d8b2884229
7
- data.tar.gz: 878dc4e0fba9a272474c78ae98a23c0565db0eb1a32009e84c1cbf6489b03418405c0d25d00d09aa8c3188310a4e0ba3b30052792f0dd5a55c4f3226ff3500fd
6
+ metadata.gz: cda714e70c20caefb01d356b281fac5dd8eb600149ecaaba77ad40dc58240e69bedc63d7259e0b4578724be756f960af07584977f3e90b9539cdb65be1c4167e
7
+ data.tar.gz: 877e5c56c488137c377a7a93fe4de8bf1b7ff7f49fbd23a1ed6ce483628d2b919edc2bed32d87eb9cace9987a55743c4f3fb5537a390ac6e1b1cbd93bdc49728
@@ -37,7 +37,7 @@ jobs:
37
37
  ruby-version: 3.2
38
38
  - run: bundle install
39
39
  - name: Test & publish code coverage
40
- uses: paambaati/codeclimate-action@v5.0.0
40
+ uses: paambaati/codeclimate-action@v6.0.0
41
41
  env:
42
42
  CC_TEST_REPORTER_ID: ${{secrets.CC_TEST_REPORTER_ID}}
43
43
  with:
data/.rubocop.yml CHANGED
@@ -45,6 +45,11 @@ Metrics/MethodLength:
45
45
  Enabled: true
46
46
  CountAsOne: ['array', 'hash']
47
47
 
48
+ Metrics/ModuleLength:
49
+ Enabled: true
50
+ Exclude:
51
+ - 'lib/itax_code/utils.rb'
52
+
48
53
  Style/Documentation:
49
54
  Enabled: false
50
55
 
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## [2.0.4](https://github.com/matteoredz/itax-code/compare/v2.0.3...v2.0.4) (2024-05-02)
4
+
5
+
6
+ ### Continuous Integration
7
+
8
+ * update paambaati/codeclimate-action to v6.0.0 ([#55](https://github.com/matteoredz/itax-code/issues/55)) ([e7aad01](https://github.com/matteoredz/itax-code/commit/e7aad0168aa18df97235171082e9bd40287dee84))
9
+
10
+
11
+ ### Code Refactoring
12
+
13
+ * converted Utils class in module ([#53](https://github.com/matteoredz/itax-code/issues/53)) ([99dddee](https://github.com/matteoredz/itax-code/commit/99dddee715b3bc5deccd27c6734832e7f9ec7cd0))
14
+
3
15
  ## [2.0.3](https://github.com/matteoredz/itax-code/compare/v2.0.2...v2.0.3) (2024-02-20)
4
16
 
5
17
 
@@ -22,7 +22,7 @@ module ItaxCode
22
22
  # @option data [String] :gender The user gender
23
23
  # @option data [String, Date] :birthdate The user birthdate
24
24
  # @option data [String] :birthplace The user birthplace
25
- def initialize(data = {}, utils = Utils.new)
25
+ def initialize(data = {}, utils = Utils)
26
26
  @utils = utils
27
27
 
28
28
  @surname = data[:surname]
@@ -8,7 +8,7 @@ module ItaxCode
8
8
  #
9
9
  # @param [String] tax_code
10
10
  # @param [Utils] utils
11
- def initialize(tax_code, utils = Utils.new)
11
+ def initialize(tax_code, utils = Utils)
12
12
  @tax_code = tax_code
13
13
  @utils = utils
14
14
  end
@@ -15,7 +15,7 @@ module ItaxCode
15
15
 
16
16
  # @param [String] tax_code
17
17
  # @param [Utils] utils
18
- def initialize(tax_code, utils = Utils.new)
18
+ def initialize(tax_code, utils = Utils)
19
19
  @tax_code = tax_code&.upcase
20
20
  @utils = utils
21
21
 
@@ -4,148 +4,152 @@ require "csv"
4
4
  require "itax_code/transliterator"
5
5
 
6
6
  module ItaxCode
7
- class Utils
8
- def blank?(obj)
9
- obj.respond_to?(:empty?) ? !!obj.empty? : !obj
10
- end
11
-
12
- def present?(obj)
13
- !blank?(obj)
14
- end
15
-
16
- def slugged(string)
17
- transliterated = transliterate(string.downcase.strip)
18
- transliterated.gsub(/[^\w-]+/, "-").gsub(/-{2,}/, "-").gsub(/^-+|-+$/, "")
19
- end
20
-
21
- def transliterate(string)
22
- return string if string.ascii_only?
23
-
24
- transliterator = Transliterator.new
25
- transliterator.transliterate(string.unicode_normalize(:nfc))
26
- end
27
-
28
- def tax_code_sections_regex
29
- /^([A-Z]{3})([A-Z]{3})
30
- (([A-Z\d]{2})([ABCDEHLMPRST]{1})([A-Z\d]{2}))
31
- ([A-Z]{1}[A-Z\d]{3})
32
- ([A-Z]{1})$/x
33
- end
34
-
35
- def months
36
- %w[A B C D E H L M P R S T]
37
- end
7
+ module Utils
8
+ class << self
9
+ def blank?(obj)
10
+ obj.respond_to?(:empty?) ? !!obj.empty? : !obj
11
+ end
38
12
 
39
- def consonants
40
- %w[b c d f g h j k l m n p q r s t v w x y z]
41
- end
13
+ def present?(obj)
14
+ !blank?(obj)
15
+ end
42
16
 
43
- def vowels
44
- %w[a e i o u]
45
- end
17
+ def slugged(string)
18
+ transliterated = transliterate(string.downcase.strip)
19
+ transliterated.gsub(/[^\w-]+/, "-").gsub(/-{2,}/, "-").gsub(/^-+|-+$/, "")
20
+ end
46
21
 
47
- def cin
48
- {
49
- "0" => [0, 1],
50
- "1" => [1, 0],
51
- "2" => [2, 5],
52
- "3" => [3, 7],
53
- "4" => [4, 9],
54
- "5" => [5, 13],
55
- "6" => [6, 15],
56
- "7" => [7, 17],
57
- "8" => [8, 19],
58
- "9" => [9, 21],
59
- "A" => [0, 1],
60
- "B" => [1, 0],
61
- "C" => [2, 5],
62
- "D" => [3, 7],
63
- "E" => [4, 9],
64
- "F" => [5, 13],
65
- "G" => [6, 15],
66
- "H" => [7, 17],
67
- "I" => [8, 19],
68
- "J" => [9, 21],
69
- "K" => [10, 2],
70
- "L" => [11, 4],
71
- "M" => [12, 18],
72
- "N" => [13, 20],
73
- "O" => [14, 11],
74
- "P" => [15, 3],
75
- "Q" => [16, 6],
76
- "R" => [17, 8],
77
- "S" => [18, 12],
78
- "T" => [19, 14],
79
- "U" => [20, 16],
80
- "V" => [21, 10],
81
- "W" => [22, 22],
82
- "X" => [23, 25],
83
- "Y" => [24, 24],
84
- "Z" => [25, 23]
85
- }
86
- end
22
+ def transliterate(string)
23
+ return string if string.ascii_only?
87
24
 
88
- def cin_remainders
89
- ("A".."Z").to_a
90
- end
25
+ transliterator = Transliterator.new
26
+ transliterator.transliterate(string.unicode_normalize(:nfc))
27
+ end
91
28
 
92
- def omocodia
93
- {
94
- "0": "L", "1": "M", "2": "N", "3": "P", "4": "Q",
95
- "5": "R", "6": "S", "7": "T", "8": "U", "9": "V"
96
- }
97
- end
29
+ def tax_code_sections_regex
30
+ /^([A-Z]{3})([A-Z]{3})
31
+ (([A-Z\d]{2})([ABCDEHLMPRST]{1})([A-Z\d]{2}))
32
+ ([A-Z]{1}[A-Z\d]{3})
33
+ ([A-Z]{1})$/x
34
+ end
98
35
 
99
- def omocodia_digits
100
- omocodia.keys.join
101
- end
36
+ def months
37
+ %w[A B C D E H L M P R S T]
38
+ end
102
39
 
103
- def omocodia_letters
104
- omocodia.values.join
105
- end
40
+ def omocodia_indexes
41
+ [6, 7, 9, 10, 12, 13, 14].reverse
42
+ end
106
43
 
107
- def omocodia_indexes
108
- [6, 7, 9, 10, 12, 13, 14].reverse
109
- end
44
+ def omocodia_indexes_combos
45
+ (1..omocodia_indexes.size).flat_map do |index|
46
+ omocodia_indexes.combination(index).to_a
47
+ end
48
+ end
110
49
 
111
- def omocodia_indexes_combos
112
- (1..omocodia_indexes.size).flat_map do |index|
113
- omocodia_indexes.combination(index).to_a
50
+ def omocodia_encode(val)
51
+ val.tr omocodia_digits, omocodia_letters
114
52
  end
115
- end
116
53
 
117
- def omocodia_encode(val)
118
- val.tr omocodia_digits, omocodia_letters
119
- end
54
+ def omocodia_decode(val)
55
+ val.tr omocodia_letters, omocodia_digits
56
+ end
120
57
 
121
- def omocodia_decode(val)
122
- val.tr omocodia_letters, omocodia_digits
123
- end
58
+ def extract_consonants(str)
59
+ str.select { |c| consonants.include? c }.join
60
+ end
124
61
 
125
- def extract_consonants(str)
126
- str.select { |c| consonants.include? c }.join
127
- end
62
+ def extract_vowels(str)
63
+ str.select { |c| vowels.include? c }.join
64
+ end
128
65
 
129
- def extract_vowels(str)
130
- str.select { |c| vowels.include? c }.join
131
- end
66
+ def encode_cin(code)
67
+ cin_tot = 0
132
68
 
133
- def encode_cin(code)
134
- cin_tot = 0
69
+ code[0..14].each_char.with_index do |char, i|
70
+ cin_tot += cin[char][((i + 1) % 2).to_i]
71
+ end
135
72
 
136
- code[0..14].each_char.with_index do |char, i|
137
- cin_tot += cin[char][((i + 1) % 2).to_i]
73
+ cin_remainders[cin_tot % 26]
138
74
  end
139
75
 
140
- cin_remainders[cin_tot % 26]
141
- end
76
+ def cities
77
+ CSV.foreach("#{__dir__}/data/cities.csv", headers: true)
78
+ end
142
79
 
143
- def cities
144
- CSV.foreach("#{__dir__}/data/cities.csv", headers: true)
145
- end
80
+ def countries
81
+ CSV.foreach("#{__dir__}/data/countries.csv", headers: true)
82
+ end
146
83
 
147
- def countries
148
- CSV.foreach("#{__dir__}/data/countries.csv", headers: true)
84
+ private
85
+
86
+ def omocodia_letters
87
+ omocodia.values.join
88
+ end
89
+
90
+ def omocodia_digits
91
+ omocodia.keys.join
92
+ end
93
+
94
+ def consonants
95
+ %w[b c d f g h j k l m n p q r s t v w x y z]
96
+ end
97
+
98
+ def vowels
99
+ %w[a e i o u]
100
+ end
101
+
102
+ def cin
103
+ {
104
+ "0" => [0, 1],
105
+ "1" => [1, 0],
106
+ "2" => [2, 5],
107
+ "3" => [3, 7],
108
+ "4" => [4, 9],
109
+ "5" => [5, 13],
110
+ "6" => [6, 15],
111
+ "7" => [7, 17],
112
+ "8" => [8, 19],
113
+ "9" => [9, 21],
114
+ "A" => [0, 1],
115
+ "B" => [1, 0],
116
+ "C" => [2, 5],
117
+ "D" => [3, 7],
118
+ "E" => [4, 9],
119
+ "F" => [5, 13],
120
+ "G" => [6, 15],
121
+ "H" => [7, 17],
122
+ "I" => [8, 19],
123
+ "J" => [9, 21],
124
+ "K" => [10, 2],
125
+ "L" => [11, 4],
126
+ "M" => [12, 18],
127
+ "N" => [13, 20],
128
+ "O" => [14, 11],
129
+ "P" => [15, 3],
130
+ "Q" => [16, 6],
131
+ "R" => [17, 8],
132
+ "S" => [18, 12],
133
+ "T" => [19, 14],
134
+ "U" => [20, 16],
135
+ "V" => [21, 10],
136
+ "W" => [22, 22],
137
+ "X" => [23, 25],
138
+ "Y" => [24, 24],
139
+ "Z" => [25, 23]
140
+ }
141
+ end
142
+
143
+ def cin_remainders
144
+ ("A".."Z").to_a
145
+ end
146
+
147
+ def omocodia
148
+ {
149
+ "0": "L", "1": "M", "2": "N", "3": "P", "4": "Q",
150
+ "5": "R", "6": "S", "7": "T", "8": "U", "9": "V"
151
+ }
152
+ end
149
153
  end
150
154
  end
151
155
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ItaxCode
4
- VERSION = "2.0.3"
4
+ VERSION = "2.0.4"
5
5
  end
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: 2.0.3
4
+ version: 2.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matteo Rossi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-02-20 00:00:00.000000000 Z
11
+ date: 2024-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: csv