itax_code 0.3.0 → 0.4.0

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: 75e7183f6da4c2c4492b53d5942521ff51a9987862016e9b07ece6f0ee41d710
4
- data.tar.gz: 89b10833a629223826fd6be3e8b40f04c1e6c6f7fe253e52321277d9ac664e88
3
+ metadata.gz: ef915bc679fc9d2e15a5935b64e4c31cab6b638d0dc077d25f1f3ba7ab2859ef
4
+ data.tar.gz: 5c4ad64f192cae5530e5a434984539b9f5c0e27ad771d4bbd461118151ba5472
5
5
  SHA512:
6
- metadata.gz: 67326622ca594d800c0cc30518fcc396182d7b1c8c47da3440eb04f057f4411730753337ab2d2f290f554c9be8eb3f0ad0765a539d8a68358204cc1a5a44fe37
7
- data.tar.gz: 280471f1325998e1712b7541e43a579a06b512198470c507d268ce353faeca508bdb2f01f5f7a57b6e874c1e6b9c3494cc3983b706bb737ecd5583220a3c38d1
6
+ metadata.gz: 0f80f432773b74fe19d74312c249279204681f211ab73bdaf60bde1c4a4fac1eace749a2bfaae75a38cf692e08b42f88723d27de9e9b29da81580980e9a79039
7
+ data.tar.gz: c0758b8d0fc862dd67e5a50842c17723368cbcc7a9e987c3e9d2683e992f55fb346cc6bc2e87374069304f247d1d0e24917c5eb0eee8b9d67b665444f79c0984
@@ -11,7 +11,7 @@ jobs:
11
11
  lint:
12
12
  runs-on: ubuntu-latest
13
13
  steps:
14
- - uses: actions/checkout@v2
14
+ - uses: actions/checkout@v3
15
15
  - uses: ruby/setup-ruby@v1
16
16
  with:
17
17
  bundler-cache: true
@@ -5,6 +5,10 @@ on:
5
5
  branches:
6
6
  - main
7
7
 
8
+ permissions:
9
+ contents: write
10
+ pull-requests: write
11
+
8
12
  jobs:
9
13
  release-please:
10
14
  runs-on: ubuntu-latest
@@ -16,7 +16,7 @@ jobs:
16
16
  matrix:
17
17
  ruby: [2.5, 2.6, 2.7, '3.0', 3.1, head]
18
18
  steps:
19
- - uses: actions/checkout@v2
19
+ - uses: actions/checkout@v3
20
20
  - uses: ruby/setup-ruby@v1
21
21
  with:
22
22
  bundler-cache: true
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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source "https://rubygems.org"
2
4
 
3
5
  gemspec
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "bundler/gem_tasks"
2
4
  require "rake/testtask"
3
5
 
data/bin/console CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require "bundler/setup"
4
5
  require "itax_code"
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
@@ -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
@@ -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 list
18
- chars = tax_code[0..14].chars
19
- (omocodes(:decode, chars) + omocodes(:encode, chars)).uniq
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 omocodes(action, chars)
25
- utils.omocodia_subs_indexes.reverse.map do |i|
26
- chars[i] = utils.public_send("omocodia_#{action}".to_sym, chars[i])
27
- omocode(chars)
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
- def omocode(chars)
32
- code = chars.join
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
@@ -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).list,
35
+ omocodes: Omocode.new(tax_code).omocodes,
34
36
  raw: raw
35
37
  }
36
38
  end
@@ -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!(/\s*@\s*/, " at ")
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, "1": 0, "2": 5, "3": 7, "4": 9, "5": 13,
33
- "6": 15, "7": 17, "8": 19, "9": 21, "A": 1, "B": 0,
34
- "C": 5, "D": 7, "E": 9, "F": 13, "G": 15, "H": 17,
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, "1": 1, "2": 2, "3": 3, "4": 4, "5": 5,
44
- "6": 6, "7": 7, "8": 8, "9": 9, "A": 0, "B": 1,
45
- "C": 2, "D": 3, "E": 4, "F": 5, "G": 6, "H": 7,
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 omocodia_subs_indexes
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)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ItaxCode
2
4
  # Handles the validation logic.
3
5
  #
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ItaxCode
2
- VERSION = "0.3.0".freeze
4
+ VERSION = "0.4.0"
3
5
  end
data/lib/itax_code.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "active_support/all"
2
4
 
3
5
  require "itax_code/version"
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.open("lib/itax_code/data/cities.csv", "w") do |output_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.3.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-06-30 00:00:00.000000000 Z
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
- post_install_message:
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.1.2
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: []