validates_identity-pa_ruc 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/Gemfile +13 -0
- data/Gemfile.lock +126 -0
- data/LICENSE.txt +21 -0
- data/README.md +69 -0
- data/Rakefile +12 -0
- data/lib/validates_identity/pa_ruc/legal_validator.rb +81 -0
- data/lib/validates_identity/pa_ruc/person_validator.rb +43 -0
- data/lib/validates_identity/pa_ruc/version.rb +7 -0
- data/lib/validates_identity/pa_ruc.rb +20 -0
- data/validates_identity-pa_ruc.gemspec +34 -0
- metadata +91 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 187b40bdac9610cd86cff02a051ac40fb3a53c721f909c3ff41d908cccf86b2a
|
4
|
+
data.tar.gz: d865f56bd0b56c85e42ba85049d9db5960eece3286589ecaa8ee7ab3f2b4fce7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0b7f9678113ecd47c358afd0a7a9143f10a3bf1044e187bd6d88b5f24184d8fbb4eaeeb592a306ac5bf62c5094db6da55894b169de47c7ad406319bd9eb466a9
|
7
|
+
data.tar.gz: ecf7870a8d00aae47af3a77b3f6ff22ff6dcf71c4635469d35d87f2b1660761b793aa1eb6260374c0b6e0e3497c3606f91d5f62ee3e1a7cd1fd2594446ad11d4
|
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/Gemfile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
# Specify your gem's dependencies in validates_identity-pa_ruc.gemspec
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
gem 'jazz_fingers'
|
9
|
+
gem 'rake'
|
10
|
+
gem 'rspec'
|
11
|
+
gem 'rubocop-rake'
|
12
|
+
gem 'rubocop-rspec'
|
13
|
+
gem 'shoulda-matchers'
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
validates_identity-pa_ruc (0.1.0)
|
5
|
+
activemodel
|
6
|
+
validates_identity (>= 0.5.0)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
activemodel (7.1.3.2)
|
12
|
+
activesupport (= 7.1.3.2)
|
13
|
+
activesupport (7.1.3.2)
|
14
|
+
base64
|
15
|
+
bigdecimal
|
16
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
17
|
+
connection_pool (>= 2.2.5)
|
18
|
+
drb
|
19
|
+
i18n (>= 1.6, < 2)
|
20
|
+
minitest (>= 5.1)
|
21
|
+
mutex_m
|
22
|
+
tzinfo (~> 2.0)
|
23
|
+
amazing_print (1.5.0)
|
24
|
+
ast (2.4.2)
|
25
|
+
base64 (0.2.0)
|
26
|
+
bigdecimal (3.1.6)
|
27
|
+
byebug (11.1.3)
|
28
|
+
coderay (1.1.3)
|
29
|
+
concurrent-ruby (1.2.3)
|
30
|
+
connection_pool (2.4.1)
|
31
|
+
coolline (0.5.0)
|
32
|
+
unicode_utils (~> 1.4)
|
33
|
+
diff-lcs (1.5.1)
|
34
|
+
drb (2.2.0)
|
35
|
+
ruby2_keywords
|
36
|
+
i18n (1.14.1)
|
37
|
+
concurrent-ruby (~> 1.0)
|
38
|
+
jazz_fingers (6.2.0)
|
39
|
+
amazing_print (~> 1.3)
|
40
|
+
pry (~> 0.10)
|
41
|
+
pry-byebug (~> 3.9)
|
42
|
+
pry-coolline (~> 0.2)
|
43
|
+
json (2.7.1)
|
44
|
+
language_server-protocol (3.17.0.3)
|
45
|
+
method_source (1.0.0)
|
46
|
+
minitest (5.22.2)
|
47
|
+
mutex_m (0.2.0)
|
48
|
+
parallel (1.24.0)
|
49
|
+
parser (3.3.0.5)
|
50
|
+
ast (~> 2.4.1)
|
51
|
+
racc
|
52
|
+
pry (0.14.2)
|
53
|
+
coderay (~> 1.1)
|
54
|
+
method_source (~> 1.0)
|
55
|
+
pry-byebug (3.10.1)
|
56
|
+
byebug (~> 11.0)
|
57
|
+
pry (>= 0.13, < 0.15)
|
58
|
+
pry-coolline (0.2.6)
|
59
|
+
coolline (~> 0.5)
|
60
|
+
pry (~> 0.13)
|
61
|
+
racc (1.7.3)
|
62
|
+
rainbow (3.1.1)
|
63
|
+
rake (13.1.0)
|
64
|
+
regexp_parser (2.9.0)
|
65
|
+
rexml (3.2.6)
|
66
|
+
rspec (3.13.0)
|
67
|
+
rspec-core (~> 3.13.0)
|
68
|
+
rspec-expectations (~> 3.13.0)
|
69
|
+
rspec-mocks (~> 3.13.0)
|
70
|
+
rspec-core (3.13.0)
|
71
|
+
rspec-support (~> 3.13.0)
|
72
|
+
rspec-expectations (3.13.0)
|
73
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
74
|
+
rspec-support (~> 3.13.0)
|
75
|
+
rspec-mocks (3.13.0)
|
76
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
77
|
+
rspec-support (~> 3.13.0)
|
78
|
+
rspec-support (3.13.1)
|
79
|
+
rubocop (1.60.2)
|
80
|
+
json (~> 2.3)
|
81
|
+
language_server-protocol (>= 3.17.0)
|
82
|
+
parallel (~> 1.10)
|
83
|
+
parser (>= 3.3.0.2)
|
84
|
+
rainbow (>= 2.2.2, < 4.0)
|
85
|
+
regexp_parser (>= 1.8, < 3.0)
|
86
|
+
rexml (>= 3.2.5, < 4.0)
|
87
|
+
rubocop-ast (>= 1.30.0, < 2.0)
|
88
|
+
ruby-progressbar (~> 1.7)
|
89
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
90
|
+
rubocop-ast (1.30.0)
|
91
|
+
parser (>= 3.2.1.0)
|
92
|
+
rubocop-capybara (2.20.0)
|
93
|
+
rubocop (~> 1.41)
|
94
|
+
rubocop-factory_bot (2.25.1)
|
95
|
+
rubocop (~> 1.41)
|
96
|
+
rubocop-rake (0.6.0)
|
97
|
+
rubocop (~> 1.0)
|
98
|
+
rubocop-rspec (2.26.1)
|
99
|
+
rubocop (~> 1.40)
|
100
|
+
rubocop-capybara (~> 2.17)
|
101
|
+
rubocop-factory_bot (~> 2.22)
|
102
|
+
ruby-progressbar (1.13.0)
|
103
|
+
ruby2_keywords (0.0.5)
|
104
|
+
shoulda-matchers (6.1.0)
|
105
|
+
activesupport (>= 5.2.0)
|
106
|
+
tzinfo (2.0.6)
|
107
|
+
concurrent-ruby (~> 1.0)
|
108
|
+
unicode-display_width (2.5.0)
|
109
|
+
unicode_utils (1.4.0)
|
110
|
+
validates_identity (0.5.2)
|
111
|
+
activemodel
|
112
|
+
|
113
|
+
PLATFORMS
|
114
|
+
x86_64-darwin-21
|
115
|
+
|
116
|
+
DEPENDENCIES
|
117
|
+
jazz_fingers
|
118
|
+
rake
|
119
|
+
rspec
|
120
|
+
rubocop-rake
|
121
|
+
rubocop-rspec
|
122
|
+
shoulda-matchers
|
123
|
+
validates_identity-pa_ruc!
|
124
|
+
|
125
|
+
BUNDLED WITH
|
126
|
+
2.5.3
|
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,69 @@
|
|
1
|
+
# ValidatesIdentity::PaRuc
|
2
|
+
|
3
|
+
This projects aims to validate Panama [Registro Único de Contribuyente](https://es.wikipedia.org/wiki/Documento_Personal_de_Identificaci%C3%B3n) identification document.
|
4
|
+
This project depends on `validates_identity` gem and is a plugin for it.
|
5
|
+
This project is based on documentations found [here](https://learn.sayari.com/interpreting-guatemalan-national-id-numbers/) and [here](https://www.mineduc.gob.gt/DIGEESP/documents/adecuacionesCurriculares/Documentos%20de%20Apoyo/C%C3%B3digos%20Departamentos-Municipios-Idiomas.pdf)
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'validates_identity-pa_ruc'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle install
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install validates_identity-pa_ruc
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
Just use as any other validator:
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
class User < ActiveRecord::Base
|
29
|
+
# :identity_type is the attribute that will be used to determine the identity type and is required
|
30
|
+
validates :identity, identity: { identity_type: :identity_type }
|
31
|
+
end
|
32
|
+
```
|
33
|
+
|
34
|
+
## Advanced Usage
|
35
|
+
|
36
|
+
New Identity Validators can be registered through the public apis of `ValidatesIdentity`
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
ValidatesIdentity.register_identity_type('CustomIdentity', CustomIdentityValidator)
|
40
|
+
```
|
41
|
+
|
42
|
+
Each Validator should have:
|
43
|
+
|
44
|
+
- a constructor with 2 params: `value` and `options` as a hash
|
45
|
+
- a `valid?` method that returns a boolean
|
46
|
+
|
47
|
+
In case of a legacy system where keys were already defined and differ from the official ones, aliases can be registered as well
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
ValidatesIdentity.register_identity_type_alias('LegacyIdentity', 'CustomIdentity')
|
51
|
+
```
|
52
|
+
|
53
|
+
## Development
|
54
|
+
|
55
|
+
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.
|
56
|
+
|
57
|
+
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).
|
58
|
+
|
59
|
+
## Contributing
|
60
|
+
|
61
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/validates_identity-pa_ruc. 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/[USERNAME]/validates_identity-pa_ruc/blob/master/CODE_OF_CONDUCT.md).
|
62
|
+
|
63
|
+
## License
|
64
|
+
|
65
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
66
|
+
|
67
|
+
## Code of Conduct
|
68
|
+
|
69
|
+
Everyone interacting in the ValidatesIdentity::PaRuc project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/validates_identity-pa_ruc/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class ValidatesIdentity
|
4
|
+
module PaRuc
|
5
|
+
class LegalValidator
|
6
|
+
VALIDATION_REGULAR_EXPRESSION = /\A([0-9]{8,9})-([1-3])-([1-2][9|0][0-9]{2})\z/i.freeze
|
7
|
+
|
8
|
+
attr_reader :value
|
9
|
+
|
10
|
+
def initialize(value)
|
11
|
+
@value = value.to_s
|
12
|
+
end
|
13
|
+
|
14
|
+
def valid?
|
15
|
+
return true if value.blank?
|
16
|
+
|
17
|
+
result.present? && valid_type? && valid_year?
|
18
|
+
end
|
19
|
+
|
20
|
+
def formatted
|
21
|
+
value
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def result
|
27
|
+
@result ||= VALIDATION_REGULAR_EXPRESSION.match(value)
|
28
|
+
end
|
29
|
+
|
30
|
+
def folio
|
31
|
+
@folio ||= result[1]
|
32
|
+
end
|
33
|
+
|
34
|
+
def type
|
35
|
+
@type ||= result[2].to_i
|
36
|
+
end
|
37
|
+
|
38
|
+
def year
|
39
|
+
@year ||= result[3].to_i
|
40
|
+
end
|
41
|
+
|
42
|
+
def valid_type?
|
43
|
+
if commercial_entity?
|
44
|
+
folio.size == 9
|
45
|
+
elsif non_commercial_entity?
|
46
|
+
folio.size == 8
|
47
|
+
elsif third_generation?
|
48
|
+
true
|
49
|
+
else
|
50
|
+
false
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def valid_year?
|
55
|
+
if commercial_entity? || non_commercial_entity?
|
56
|
+
year >= 2014
|
57
|
+
elsif third_generation?
|
58
|
+
year >= 1999 && year <= 2014
|
59
|
+
else
|
60
|
+
false
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def third_generation?
|
65
|
+
type == 1
|
66
|
+
end
|
67
|
+
|
68
|
+
def fourth_generation?
|
69
|
+
commercial_entity? || non_commercial_entity?
|
70
|
+
end
|
71
|
+
|
72
|
+
def commercial_entity?
|
73
|
+
type == 2
|
74
|
+
end
|
75
|
+
|
76
|
+
def non_commercial_entity?
|
77
|
+
type == 3
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class ValidatesIdentity
|
4
|
+
module PaRuc
|
5
|
+
class PersonValidator
|
6
|
+
VALIDATION_REGULAR_EXPRESSION = /\A([0-9A-Z]{1,2})-([1-9][0-9]{0,})-([1-9][0-9]{0,})\z/i.freeze
|
7
|
+
|
8
|
+
attr_reader :value
|
9
|
+
|
10
|
+
def initialize(value)
|
11
|
+
@value = value.to_s
|
12
|
+
end
|
13
|
+
|
14
|
+
def valid?
|
15
|
+
return true if value.blank?
|
16
|
+
|
17
|
+
birth_state.present? && birth_state_valid?
|
18
|
+
end
|
19
|
+
|
20
|
+
def formatted
|
21
|
+
value
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def result
|
27
|
+
@result ||= VALIDATION_REGULAR_EXPRESSION.match(value)
|
28
|
+
end
|
29
|
+
|
30
|
+
def birth_state
|
31
|
+
return if result.nil?
|
32
|
+
|
33
|
+
@birth_state ||= result[1]
|
34
|
+
end
|
35
|
+
|
36
|
+
def birth_state_valid?
|
37
|
+
return true if birth_state.to_i.between?(1, 13)
|
38
|
+
|
39
|
+
%w[E N PE EM KY NT NB].include?(birth_state)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'validates_identity'
|
4
|
+
require_relative 'pa_ruc/version'
|
5
|
+
|
6
|
+
class ValidatesIdentity
|
7
|
+
module PaRuc
|
8
|
+
autoload :LegalValidator, 'validates_identity/pa_ruc/legal_validator'
|
9
|
+
autoload :PersonValidator, 'validates_identity/pa_ruc/person_validator'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
# Legal
|
14
|
+
ValidatesIdentity.register_legal_identity_type('PA_RUCL', ValidatesIdentity::PaRuc::LegalValidator)
|
15
|
+
ValidatesIdentity::ShouldaMatchers.register_legal_allowed_values('PA_RUCL', %w[123456789-2-2015 10101010-1-2001 12312123-3-2040])
|
16
|
+
ValidatesIdentity::ShouldaMatchers.register_legal_disallowed_values('PA_RUCL', %w[90-234-1-23 10-0-123-123])
|
17
|
+
# Person
|
18
|
+
ValidatesIdentity.register_person_identity_type('PA_RUCP', ValidatesIdentity::PaRuc::PersonValidator)
|
19
|
+
ValidatesIdentity::ShouldaMatchers.register_person_allowed_values('PA_RUCP', %w[PE-23-123 10-1-123])
|
20
|
+
ValidatesIdentity::ShouldaMatchers.register_person_disallowed_values('PA_RUCP', %w[90-234-123 10-0123-123])
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'lib/validates_identity/pa_ruc/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'validates_identity-pa_ruc'
|
7
|
+
spec.version = ValidatesIdentity::PaRuc::VERSION
|
8
|
+
spec.authors = ['Paulo Ribeiro']
|
9
|
+
spec.email = ['plribeiro3000@gmail.com']
|
10
|
+
|
11
|
+
spec.summary = 'Validates Panama RUC Document and test it with matchers in a simple way.'
|
12
|
+
spec.homepage = 'https://github.com/plribeiro3000/validates_identity-pa_ruc'
|
13
|
+
spec.license = 'MIT'
|
14
|
+
spec.required_ruby_version = '>= 2.6.0'
|
15
|
+
|
16
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
17
|
+
spec.metadata['source_code_uri'] = 'https://github.com/plribeiro3000/validates_identity-pa_ruc/blob/master'
|
18
|
+
spec.metadata['changelog_uri'] = 'https://github.com/plribeiro3000/validates_identity-pa_ruc/blob/master/CHANGELOG.md'
|
19
|
+
|
20
|
+
# Specify which files should be added to the gem when it is released.
|
21
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
22
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
23
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
24
|
+
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
|
25
|
+
end
|
26
|
+
end
|
27
|
+
spec.bindir = 'exe'
|
28
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
29
|
+
spec.require_paths = ['lib']
|
30
|
+
|
31
|
+
spec.add_runtime_dependency 'activemodel'
|
32
|
+
spec.add_runtime_dependency 'validates_identity', '>= 0.5.0'
|
33
|
+
spec.metadata['rubygems_mfa_required'] = 'true'
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: validates_identity-pa_ruc
|
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-02-28 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
|
+
- Gemfile
|
55
|
+
- Gemfile.lock
|
56
|
+
- LICENSE.txt
|
57
|
+
- README.md
|
58
|
+
- Rakefile
|
59
|
+
- lib/validates_identity/pa_ruc.rb
|
60
|
+
- lib/validates_identity/pa_ruc/legal_validator.rb
|
61
|
+
- lib/validates_identity/pa_ruc/person_validator.rb
|
62
|
+
- lib/validates_identity/pa_ruc/version.rb
|
63
|
+
- validates_identity-pa_ruc.gemspec
|
64
|
+
homepage: https://github.com/plribeiro3000/validates_identity-pa_ruc
|
65
|
+
licenses:
|
66
|
+
- MIT
|
67
|
+
metadata:
|
68
|
+
homepage_uri: https://github.com/plribeiro3000/validates_identity-pa_ruc
|
69
|
+
source_code_uri: https://github.com/plribeiro3000/validates_identity-pa_ruc/blob/master
|
70
|
+
changelog_uri: https://github.com/plribeiro3000/validates_identity-pa_ruc/blob/master/CHANGELOG.md
|
71
|
+
rubygems_mfa_required: 'true'
|
72
|
+
post_install_message:
|
73
|
+
rdoc_options: []
|
74
|
+
require_paths:
|
75
|
+
- lib
|
76
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: 2.6.0
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
requirements: []
|
87
|
+
rubygems_version: 3.5.3
|
88
|
+
signing_key:
|
89
|
+
specification_version: 4
|
90
|
+
summary: Validates Panama RUC Document and test it with matchers in a simple way.
|
91
|
+
test_files: []
|