validates_identity-cl_rut 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +19 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/LICENSE.txt +21 -0
- data/README.md +68 -0
- data/Rakefile +12 -0
- data/lib/validates_identity/cl_rut/validator.rb +62 -0
- data/lib/validates_identity/cl_rut/version.rb +7 -0
- data/lib/validates_identity/cl_rut.rb +19 -0
- metadata +87 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2387b292aa62c605ff35ec3c7e57cc33c9e1ed19fc715cc6e3697555613b2500
|
4
|
+
data.tar.gz: ff0ca284eb1b150f1b391be86f9294bd5b61905e9fd3a2e0452856587c1ab84a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e7b51f8b2e370d7adaac10a5107e905ea325eeae10228e4d4ea354f22fb170c7f5e92df488ee3fff329e528e197976f6b351561252170990360a6f4f9dc6bec3
|
7
|
+
data.tar.gz: 6fe0653c4157f8ff5e9bd699a0effbfcf3d1a5641388e6f3b144a0d6e56db46fb3f5cc4bb52e62829f3ad4fef5f4052eb9eda57f19c4d5c1fb515058b371612f
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require:
|
2
|
+
- rubocop-rake
|
3
|
+
- rubocop-rspec
|
4
|
+
|
5
|
+
AllCops:
|
6
|
+
NewCops: enable
|
7
|
+
TargetRubyVersion: 2.6
|
8
|
+
|
9
|
+
Layout/LineLength:
|
10
|
+
Max: 150
|
11
|
+
|
12
|
+
Metrics/BlockLength:
|
13
|
+
Enabled: false
|
14
|
+
|
15
|
+
RSpec/NestedGroups:
|
16
|
+
Max: 4
|
17
|
+
|
18
|
+
Style/Documentation:
|
19
|
+
Enabled: false
|
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
validate_identity
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.3.0
|
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
6
|
+
|
7
|
+
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
|
8
|
+
|
9
|
+
## Our Standards
|
10
|
+
|
11
|
+
Examples of behavior that contributes to a positive environment for our community include:
|
12
|
+
|
13
|
+
* Demonstrating empathy and kindness toward other people
|
14
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
15
|
+
* Giving and gracefully accepting constructive feedback
|
16
|
+
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
|
17
|
+
* Focusing on what is best not just for us as individuals, but for the overall community
|
18
|
+
|
19
|
+
Examples of unacceptable behavior include:
|
20
|
+
|
21
|
+
* The use of sexualized language or imagery, and sexual attention or
|
22
|
+
advances of any kind
|
23
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
24
|
+
* Public or private harassment
|
25
|
+
* Publishing others' private information, such as a physical or email
|
26
|
+
address, without their explicit permission
|
27
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
28
|
+
professional setting
|
29
|
+
|
30
|
+
## Enforcement Responsibilities
|
31
|
+
|
32
|
+
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
|
33
|
+
|
34
|
+
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
|
35
|
+
|
36
|
+
## Scope
|
37
|
+
|
38
|
+
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
|
39
|
+
|
40
|
+
## Enforcement
|
41
|
+
|
42
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at plribeiro3000@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
|
43
|
+
|
44
|
+
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
|
45
|
+
|
46
|
+
## Enforcement Guidelines
|
47
|
+
|
48
|
+
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
|
49
|
+
|
50
|
+
### 1. Correction
|
51
|
+
|
52
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
|
53
|
+
|
54
|
+
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
|
55
|
+
|
56
|
+
### 2. Warning
|
57
|
+
|
58
|
+
**Community Impact**: A violation through a single incident or series of actions.
|
59
|
+
|
60
|
+
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
|
61
|
+
|
62
|
+
### 3. Temporary Ban
|
63
|
+
|
64
|
+
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
|
65
|
+
|
66
|
+
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
|
67
|
+
|
68
|
+
### 4. Permanent Ban
|
69
|
+
|
70
|
+
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
|
71
|
+
|
72
|
+
**Consequence**: A permanent ban from any sort of public interaction within the community.
|
73
|
+
|
74
|
+
## Attribution
|
75
|
+
|
76
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
|
77
|
+
available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
78
|
+
|
79
|
+
Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
|
80
|
+
|
81
|
+
[homepage]: https://www.contributor-covenant.org
|
82
|
+
|
83
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
84
|
+
https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2024 Paulo Ribeiro
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
# ValidatesIdentity::ClRut
|
2
|
+
|
3
|
+
This projects aims to validate Chile [RUT](https://es.wikipedia.org/wiki/Rol_%C3%9Anico_Tributario) identification document.
|
4
|
+
This project depends on `validates_identity` gem and is a plugin for it.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'validates_identity-cl_rut'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle install
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install validates_identity-cl_rut
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
Just use as any other validator:
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
class User < ActiveRecord::Base
|
28
|
+
# :identity_type is the attribute that will be used to determine the identity type and is required
|
29
|
+
validates :identity, identity: { identity_type: :identity_type }
|
30
|
+
end
|
31
|
+
```
|
32
|
+
|
33
|
+
## Advanced Usage
|
34
|
+
|
35
|
+
New Identity Validators can be registered through the public apis of `ValidatesIdentity`
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
ValidatesIdentity.register_identity_type('CustomIdentity', CustomIdentityValidator)
|
39
|
+
```
|
40
|
+
|
41
|
+
Each Validator should have:
|
42
|
+
|
43
|
+
- a constructor with 2 params: `value` and `options` as a hash
|
44
|
+
- a `valid?` method that returns a boolean
|
45
|
+
|
46
|
+
In case of a legacy system where keys were already defined and differ from the official ones, aliases can be registered as well
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
ValidatesIdentity.register_identity_type_alias('LegacyIdentity', 'CustomIdentity')
|
50
|
+
```
|
51
|
+
|
52
|
+
## Development
|
53
|
+
|
54
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
55
|
+
|
56
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
57
|
+
|
58
|
+
## Contributing
|
59
|
+
|
60
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/plribeiro3000/validates_identity-cl_rut. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/plribeiro3000/validates_identity-cl_rut/blob/master/CODE_OF_CONDUCT.md).
|
61
|
+
|
62
|
+
## License
|
63
|
+
|
64
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
65
|
+
|
66
|
+
## Code of Conduct
|
67
|
+
|
68
|
+
Everyone interacting in the ValidatesIdentity::ClRut project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/plribeiro3000/validates_identity-cl_rut/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class ValidatesIdentity
|
4
|
+
module ClRut
|
5
|
+
class Validator
|
6
|
+
VALIDATION_REGULAR_EXPRESSION = /^(\d{2})\.?(\d{3})\.?(\d{3})-?(\d{1}|K)$/.freeze
|
7
|
+
|
8
|
+
attr_reader :value
|
9
|
+
|
10
|
+
def initialize(value)
|
11
|
+
@value = value
|
12
|
+
end
|
13
|
+
|
14
|
+
def valid?
|
15
|
+
return true if value.blank?
|
16
|
+
return false if number.nil?
|
17
|
+
|
18
|
+
verifier_digit == calculated_verifier_digit
|
19
|
+
end
|
20
|
+
|
21
|
+
def formatted
|
22
|
+
return if result.nil?
|
23
|
+
|
24
|
+
"#{result[1]}.#{result[2]}.#{result[3]}-#{result[4]}"
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def result
|
30
|
+
@result ||= VALIDATION_REGULAR_EXPRESSION.match(value)
|
31
|
+
end
|
32
|
+
|
33
|
+
def number
|
34
|
+
return if result.nil?
|
35
|
+
|
36
|
+
@number ||= "#{result[1]}#{result[2]}#{result[3]}"
|
37
|
+
end
|
38
|
+
|
39
|
+
def verifier_digit
|
40
|
+
result[4].to_s
|
41
|
+
end
|
42
|
+
|
43
|
+
def calculated_verifier_digit
|
44
|
+
sum = multiply_and_sum([3, 2, 7, 6, 5, 4, 3, 2], number)
|
45
|
+
rest = sum % 11
|
46
|
+
difference = 11 - rest
|
47
|
+
|
48
|
+
case difference
|
49
|
+
when 11 then '0'
|
50
|
+
when 10 then 'K'
|
51
|
+
else difference.to_s
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def multiply_and_sum(array, number)
|
56
|
+
multiplied = []
|
57
|
+
number.scan(/\d{1}/).each_with_index { |e, i| multiplied[i] = e.to_i * array[i] }
|
58
|
+
multiplied.inject { |s, e| s + e }
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'validates_identity'
|
4
|
+
require_relative 'cl_rut/version'
|
5
|
+
|
6
|
+
class ValidatesIdentity
|
7
|
+
module ClRut
|
8
|
+
autoload :Validator, 'validates_identity/cl_rut/validator'
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
# Legal
|
13
|
+
ValidatesIdentity.register_legal_identity_type('CL_RUT_LEGAL', ValidatesIdentity::ClRut::Validator)
|
14
|
+
ValidatesIdentity::ShouldaMatchers.register_legal_allowed_values('CL_RUT_LEGAL', %w[760864285 76.086.428-5 220604497 22.060.449-7])
|
15
|
+
ValidatesIdentity::ShouldaMatchers.register_legal_disallowed_values('CL_RUT_LEGAL', %w[76086428K 76.086.428-K 220604492 22.060.449-2])
|
16
|
+
# Person
|
17
|
+
ValidatesIdentity.register_person_identity_type('CL_RUT_PERSON', ValidatesIdentity::ClRut::Validator)
|
18
|
+
ValidatesIdentity::ShouldaMatchers.register_person_allowed_values('CL_RUT_PERSON', %w[760864285 76.086.428-5 220604497 22.060.449-7])
|
19
|
+
ValidatesIdentity::ShouldaMatchers.register_person_disallowed_values('CL_RUT_PERSON', %w[76086428K 76.086.428-K 220604492 22.060.449-2])
|
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: validates_identity-cl_rut
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Paulo Ribeiro
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-03-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activemodel
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: validates_identity
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.5.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.5.0
|
41
|
+
description:
|
42
|
+
email:
|
43
|
+
- plribeiro3000@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".rspec"
|
49
|
+
- ".rubocop.yml"
|
50
|
+
- ".ruby-gemset"
|
51
|
+
- ".ruby-version"
|
52
|
+
- CHANGELOG.md
|
53
|
+
- CODE_OF_CONDUCT.md
|
54
|
+
- LICENSE.txt
|
55
|
+
- README.md
|
56
|
+
- Rakefile
|
57
|
+
- lib/validates_identity/cl_rut.rb
|
58
|
+
- lib/validates_identity/cl_rut/validator.rb
|
59
|
+
- lib/validates_identity/cl_rut/version.rb
|
60
|
+
homepage: https://github.com/plribeiro3000/validates_identity-cl_rut
|
61
|
+
licenses:
|
62
|
+
- MIT
|
63
|
+
metadata:
|
64
|
+
homepage_uri: https://github.com/plribeiro3000/validates_identity-cl_rut
|
65
|
+
source_code_uri: https://github.com/plribeiro3000/validates_identity-cl_rut/blob/master
|
66
|
+
changelog_uri: https://github.com/plribeiro3000/validates_identity-cl_rut/blob/master/CHANGELOG.md
|
67
|
+
rubygems_mfa_required: 'true'
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options: []
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: 2.6.0
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
requirements: []
|
83
|
+
rubygems_version: 3.5.3
|
84
|
+
signing_key:
|
85
|
+
specification_version: 4
|
86
|
+
summary: Validates Chile RUT Document and test it with matchers in a simple way.
|
87
|
+
test_files: []
|