itax_code 0.1.2
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 +7 -0
- data/.gitignore +12 -0
- data/.rubocop.yml +30 -0
- data/.travis.yml +6 -0
- data/CHANGELOG.md +9 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +73 -0
- data/README.md +84 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/itax_code.gemspec +36 -0
- data/lib/itax_code.rb +68 -0
- data/lib/itax_code/data/countries.json +278 -0
- data/lib/itax_code/data/municipalities.json +13833 -0
- data/lib/itax_code/encoder.rb +97 -0
- data/lib/itax_code/parser.rb +114 -0
- data/lib/itax_code/utils.rb +112 -0
- data/lib/itax_code/validator.rb +44 -0
- data/lib/itax_code/version.rb +3 -0
- metadata +192 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f79a865df5d202807046608d8b774ae21b05426d6418815884ff808cae75d79f
|
4
|
+
data.tar.gz: fee682091af5907dce1ef0ac32ddc16fb44cba9956e1c04534ba1505750e2c5f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1f4552edfa936dd8224abccd20861236bcc51311d84342e4e9b0516f7b73b0fc7496a957cd5957ead747f6f44885ada49ea38fbfbf96d8444f252472e1eecc73
|
7
|
+
data.tar.gz: 27ae449fc19eef5d2f30e0ca7e581837683ec2353e8003798f40ba23a05b0efa9a6f0d498c1f6927d7e7b0042a85e8940a3f09bfbb6ef8359d011bfc0ea20f97
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
---
|
2
|
+
require:
|
3
|
+
- rubocop-minitest
|
4
|
+
- rubocop-performance
|
5
|
+
|
6
|
+
Bundler/OrderedGems:
|
7
|
+
Enabled: false
|
8
|
+
|
9
|
+
Layout/IndentationConsistency:
|
10
|
+
Enabled: true
|
11
|
+
EnforcedStyle: indented_internal_methods
|
12
|
+
|
13
|
+
Layout/LineLength:
|
14
|
+
Enabled: true
|
15
|
+
Max: 80
|
16
|
+
|
17
|
+
Metrics/MethodLength:
|
18
|
+
Enabled: true
|
19
|
+
CountAsOne: ['array', 'hash']
|
20
|
+
|
21
|
+
Style/Documentation:
|
22
|
+
Enabled: false
|
23
|
+
|
24
|
+
Style/FrozenStringLiteralComment:
|
25
|
+
Enabled: false
|
26
|
+
|
27
|
+
Style/StringLiterals:
|
28
|
+
Enabled: true
|
29
|
+
EnforcedStyle: double_quotes
|
30
|
+
...
|
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at mttrss5@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [https://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: https://contributor-covenant.org
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
itax_code (0.1.2)
|
5
|
+
activesupport
|
6
|
+
rake
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
activesupport (6.0.3.4)
|
12
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
13
|
+
i18n (>= 0.7, < 2)
|
14
|
+
minitest (~> 5.1)
|
15
|
+
tzinfo (~> 1.1)
|
16
|
+
zeitwerk (~> 2.2, >= 2.2.2)
|
17
|
+
ast (2.4.1)
|
18
|
+
byebug (11.1.3)
|
19
|
+
concurrent-ruby (1.1.7)
|
20
|
+
docile (1.3.2)
|
21
|
+
i18n (1.8.5)
|
22
|
+
concurrent-ruby (~> 1.0)
|
23
|
+
minitest (5.14.2)
|
24
|
+
mocha (1.11.2)
|
25
|
+
parallel (1.20.0)
|
26
|
+
parser (2.7.2.0)
|
27
|
+
ast (~> 2.4.1)
|
28
|
+
rainbow (3.0.0)
|
29
|
+
rake (13.0.1)
|
30
|
+
regexp_parser (1.8.2)
|
31
|
+
rexml (3.2.4)
|
32
|
+
rubocop (1.3.1)
|
33
|
+
parallel (~> 1.10)
|
34
|
+
parser (>= 2.7.1.5)
|
35
|
+
rainbow (>= 2.2.2, < 4.0)
|
36
|
+
regexp_parser (>= 1.8)
|
37
|
+
rexml
|
38
|
+
rubocop-ast (>= 1.1.1)
|
39
|
+
ruby-progressbar (~> 1.7)
|
40
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
41
|
+
rubocop-ast (1.1.1)
|
42
|
+
parser (>= 2.7.1.5)
|
43
|
+
rubocop-minitest (0.10.1)
|
44
|
+
rubocop (>= 0.87)
|
45
|
+
rubocop-performance (1.9.0)
|
46
|
+
rubocop (>= 0.90.0, < 2.0)
|
47
|
+
rubocop-ast (>= 0.4.0)
|
48
|
+
ruby-progressbar (1.10.1)
|
49
|
+
simplecov (0.19.1)
|
50
|
+
docile (~> 1.1)
|
51
|
+
simplecov-html (~> 0.11)
|
52
|
+
simplecov-html (0.12.3)
|
53
|
+
thread_safe (0.3.6)
|
54
|
+
tzinfo (1.2.8)
|
55
|
+
thread_safe (~> 0.1)
|
56
|
+
unicode-display_width (1.7.0)
|
57
|
+
zeitwerk (2.4.1)
|
58
|
+
|
59
|
+
PLATFORMS
|
60
|
+
ruby
|
61
|
+
|
62
|
+
DEPENDENCIES
|
63
|
+
byebug
|
64
|
+
itax_code!
|
65
|
+
minitest
|
66
|
+
mocha
|
67
|
+
rubocop
|
68
|
+
rubocop-minitest
|
69
|
+
rubocop-performance
|
70
|
+
simplecov
|
71
|
+
|
72
|
+
BUNDLED WITH
|
73
|
+
2.1.4
|
data/README.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# ItaxCode
|
2
|
+
|
3
|
+
`ItaxCode` is a Ruby Gem to encode and decode Italian tax code (Codice Fiscale).
|
4
|
+
|
5
|
+
It handles common operations on Italian tax code like, for instance, encoding, decoding and validation.
|
6
|
+
It also handles [omocodia](https://it.wikipedia.org/wiki/Omocodia) complexity.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem "itax_code"
|
14
|
+
```
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle install
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install itax_code
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
### Encode
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
ItaxCode.generate(
|
30
|
+
surname: "Rossi",
|
31
|
+
name: "Mario",
|
32
|
+
gender: "M", # can be M or F
|
33
|
+
birthdate: "1980-1-1", # can be String, Time, Date or DateTime
|
34
|
+
birthplace: "Milano"
|
35
|
+
)
|
36
|
+
```
|
37
|
+
|
38
|
+
### Decode
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
ItaxCode.decode("RSSMRA80A01F205X")
|
42
|
+
```
|
43
|
+
|
44
|
+
### Validate
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
ItaxCode.valid?(
|
48
|
+
"RSSMRA80A01F205X",
|
49
|
+
{
|
50
|
+
surname: "Rossi",
|
51
|
+
name: "Mario",
|
52
|
+
gender: "M",
|
53
|
+
birthdate: "1980-1-1",
|
54
|
+
birthplace: "Milano"
|
55
|
+
}
|
56
|
+
)
|
57
|
+
```
|
58
|
+
|
59
|
+
## Development
|
60
|
+
|
61
|
+
After checking out the repo, run `bin/setup` to install dependencies.
|
62
|
+
Then, run `rake test` to run the tests.
|
63
|
+
You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
64
|
+
|
65
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
66
|
+
To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`,
|
67
|
+
which will create a git tag for the version, push git commits and tags,
|
68
|
+
and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
69
|
+
|
70
|
+
## Contributing
|
71
|
+
|
72
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/matteoredz/itax_code.
|
73
|
+
This project is intended to be a safe, welcoming space for collaboration, and contributors are expected
|
74
|
+
to adhere to the [code of conduct](https://github.com/matteoredz/itax_code/blob/master/CODE_OF_CONDUCT.md).
|
75
|
+
|
76
|
+
## Code of Conduct
|
77
|
+
|
78
|
+
Everyone interacting in the ItaxCode project's codebases, issue trackers,
|
79
|
+
chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/matteoredz/itax_code/blob/master/CODE_OF_CONDUCT.md).
|
80
|
+
|
81
|
+
## Credits
|
82
|
+
|
83
|
+
I took my cue from [python-codicefiscale](https://github.com/fabiocaccamo/python-codicefiscale) repo,
|
84
|
+
coded by [Fabio Caccamo](https://github.com/fabiocaccamo) to write ItaxCode Gem.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "itax_code"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/itax_code.gemspec
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require_relative "lib/itax_code/version"
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "itax_code"
|
5
|
+
spec.version = ItaxCode::VERSION
|
6
|
+
spec.licenses = ["MIT"]
|
7
|
+
spec.authors = ["Matteo Rossi"]
|
8
|
+
spec.email = ["mttrss5@gmail.com"]
|
9
|
+
spec.summary = "Encode and decode Italian tax code (Codice Fiscale)."
|
10
|
+
spec.homepage = "https://github.com/matteoredz/itax-code"
|
11
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
|
12
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
13
|
+
spec.metadata["source_code_uri"] = "https://github.com/matteoredz/itax-code"
|
14
|
+
spec.metadata["changelog_uri"] = "https://github.com/matteoredz/itax-code/CHANGELOG.md"
|
15
|
+
|
16
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
17
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
spec.bindir = "exe"
|
23
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
+
spec.require_paths = ["lib"]
|
25
|
+
|
26
|
+
spec.add_dependency "activesupport"
|
27
|
+
spec.add_dependency "rake"
|
28
|
+
|
29
|
+
spec.add_development_dependency "byebug"
|
30
|
+
spec.add_development_dependency "minitest"
|
31
|
+
spec.add_development_dependency "mocha"
|
32
|
+
spec.add_development_dependency "rubocop"
|
33
|
+
spec.add_development_dependency "rubocop-minitest"
|
34
|
+
spec.add_development_dependency "rubocop-performance"
|
35
|
+
spec.add_development_dependency "simplecov"
|
36
|
+
end
|
data/lib/itax_code.rb
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
require "itax_code/version"
|
2
|
+
require "active_support/all"
|
3
|
+
require "itax_code/utils"
|
4
|
+
require "itax_code/encoder"
|
5
|
+
require "itax_code/parser"
|
6
|
+
require "itax_code/validator"
|
7
|
+
|
8
|
+
module ItaxCode
|
9
|
+
class << self
|
10
|
+
##
|
11
|
+
# This method encodes citizen tax code
|
12
|
+
#
|
13
|
+
# @example
|
14
|
+
#
|
15
|
+
# ItaxCode.generate({
|
16
|
+
# surname: [String]
|
17
|
+
# name: [String]
|
18
|
+
# gender: [String]
|
19
|
+
# birthdate: [Date, DateTime, Time]
|
20
|
+
# birthplace: [String]
|
21
|
+
# })
|
22
|
+
#
|
23
|
+
# @param [Hash] data The citizen data attributes
|
24
|
+
#
|
25
|
+
# @return [String]
|
26
|
+
|
27
|
+
def encode(data)
|
28
|
+
Encoder.new(data).encode
|
29
|
+
end
|
30
|
+
|
31
|
+
##
|
32
|
+
# This method decodes tax code in its components
|
33
|
+
#
|
34
|
+
# @example
|
35
|
+
#
|
36
|
+
# ItaxCode.decode("CCCFBA85D03L219P")
|
37
|
+
#
|
38
|
+
# @param [String] tax_code The citizen tax code
|
39
|
+
#
|
40
|
+
# @return [Hash]
|
41
|
+
|
42
|
+
def decode(tax_code)
|
43
|
+
Parser.new(tax_code).decode
|
44
|
+
end
|
45
|
+
|
46
|
+
##
|
47
|
+
# This method check given tax code validity
|
48
|
+
# against new one generated by citizen informations
|
49
|
+
#
|
50
|
+
# @example
|
51
|
+
#
|
52
|
+
# ItaxCode.valid?(tax_code [String], {
|
53
|
+
# surname: [String]
|
54
|
+
# name: [String]
|
55
|
+
# gender: [String]
|
56
|
+
# birthdate: [Date, DateTime, Time]
|
57
|
+
# birthplace: [String]
|
58
|
+
# })
|
59
|
+
#
|
60
|
+
# @return [true, false]
|
61
|
+
|
62
|
+
def valid?(tax_code, data)
|
63
|
+
Validator.new(data).valid?(tax_code)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
class Error < StandardError; end
|
68
|
+
end
|