chilean-rutify 0.1.1 → 1.0.0
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 +4 -4
- data/.github/ISSUE_TEMPLATE/bug_report.md +38 -0
- data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
- data/.github/workflows/reviewdog.yml +22 -0
- data/.github/workflows/rspec.yml +22 -0
- data/.rubocop.yml +6 -0
- data/Gemfile +0 -4
- data/Gemfile.lock +91 -0
- data/README.md +31 -1
- data/_config.yml +1 -0
- data/bin/console +1 -0
- data/chilean-rutify.gemspec +11 -1
- data/lib/chilean/rutify/errors.rb +3 -0
- data/lib/chilean/rutify/rut_validator.rb +6 -7
- data/lib/chilean/rutify/rutifiable.rb +28 -0
- data/lib/chilean/rutify/version.rb +1 -1
- data/lib/chilean/rutify.rb +44 -19
- metadata +128 -8
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 42fcb1be0ba27780e2b72f9faadb58beafcc80114cd558309c3758e79e376702
|
|
4
|
+
data.tar.gz: ccb57c58b04b56ca995fc9389cc43c057445cfac0e30995f7ca95c6e9269c683
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 75743ce951e3e2eac69382d39cbcada3e300cae0e029c0891f5b6d712929877170685ef0983b8a32cff3740decab6dd2d4febd0c34d4653b13f97b649b4fbf7e
|
|
7
|
+
data.tar.gz: 90c0f81067fb08f29ffdc4b26549bde3cfdd962a623753280ddd2057f3247854ef39778b9d78e5cb99cf1264058cfa558e46e07e243ec6964abd7cbec86f3800
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Bug report
|
|
3
|
+
about: Create a report to help us improve
|
|
4
|
+
title: "[BUG]"
|
|
5
|
+
labels: bug
|
|
6
|
+
assignees: mihailpozarski
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
**Describe the bug**
|
|
11
|
+
A clear and concise description of what the bug is.
|
|
12
|
+
|
|
13
|
+
**To Reproduce**
|
|
14
|
+
Steps to reproduce the behavior:
|
|
15
|
+
1. Go to '...'
|
|
16
|
+
2. Click on '....'
|
|
17
|
+
3. Scroll down to '....'
|
|
18
|
+
4. See error
|
|
19
|
+
|
|
20
|
+
**Expected behavior**
|
|
21
|
+
A clear and concise description of what you expected to happen.
|
|
22
|
+
|
|
23
|
+
**Screenshots**
|
|
24
|
+
If applicable, add screenshots to help explain your problem.
|
|
25
|
+
|
|
26
|
+
**Desktop (please complete the following information):**
|
|
27
|
+
- OS: [e.g. iOS]
|
|
28
|
+
- Browser [e.g. chrome, safari]
|
|
29
|
+
- Version [e.g. 22]
|
|
30
|
+
|
|
31
|
+
**Smartphone (please complete the following information):**
|
|
32
|
+
- Device: [e.g. iPhone6]
|
|
33
|
+
- OS: [e.g. iOS8.1]
|
|
34
|
+
- Browser [e.g. stock browser, safari]
|
|
35
|
+
- Version [e.g. 22]
|
|
36
|
+
|
|
37
|
+
**Additional context**
|
|
38
|
+
Add any other context about the problem here.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Feature request
|
|
3
|
+
about: Suggest an idea for this project
|
|
4
|
+
title: "[Feature]"
|
|
5
|
+
labels: enhancement
|
|
6
|
+
assignees: mihailpozarski
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
**Is your feature request related to a problem? Please describe.**
|
|
11
|
+
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
|
12
|
+
|
|
13
|
+
**Describe the solution you'd like**
|
|
14
|
+
A clear and concise description of what you want to happen.
|
|
15
|
+
|
|
16
|
+
**Describe alternatives you've considered**
|
|
17
|
+
A clear and concise description of any alternative solutions or features you've considered.
|
|
18
|
+
|
|
19
|
+
**Additional context**
|
|
20
|
+
Add any other context or screenshots about the feature request here.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
name: reviewdog
|
|
2
|
+
on:
|
|
3
|
+
push:
|
|
4
|
+
branches:
|
|
5
|
+
- main
|
|
6
|
+
jobs:
|
|
7
|
+
rubocop:
|
|
8
|
+
name: rubocop
|
|
9
|
+
runs-on: ubuntu-latest
|
|
10
|
+
steps:
|
|
11
|
+
- name: Check out code
|
|
12
|
+
uses: actions/checkout@v1
|
|
13
|
+
- uses: ruby/setup-ruby@v1
|
|
14
|
+
with:
|
|
15
|
+
ruby-version: 2.7.4
|
|
16
|
+
- name: rubocop
|
|
17
|
+
uses: reviewdog/action-rubocop@v1
|
|
18
|
+
with:
|
|
19
|
+
rubocop_version: gemfile
|
|
20
|
+
rubocop_extensions: rubocop-rails:gemfile rubocop-rspec:gemfile rubocop-performance:gemfile
|
|
21
|
+
github_token: ${{ secrets.github_token }}
|
|
22
|
+
reporter: github-check
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
name: rspec
|
|
2
|
+
on:
|
|
3
|
+
push:
|
|
4
|
+
branches:
|
|
5
|
+
- main
|
|
6
|
+
jobs:
|
|
7
|
+
rspec:
|
|
8
|
+
name: rspec
|
|
9
|
+
runs-on: ubuntu-latest
|
|
10
|
+
steps:
|
|
11
|
+
- name: Check out code
|
|
12
|
+
uses: actions/checkout@v1
|
|
13
|
+
- uses: ruby/setup-ruby@v1
|
|
14
|
+
with:
|
|
15
|
+
ruby-version: 2.7.4
|
|
16
|
+
- name: Install bundler
|
|
17
|
+
run: |
|
|
18
|
+
gem install bundler
|
|
19
|
+
bundle install --retry=2
|
|
20
|
+
- name: Run rspec
|
|
21
|
+
run: bundle exec rspec
|
|
22
|
+
|
data/.rubocop.yml
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
chilean-rutify (1.0.0)
|
|
5
|
+
|
|
6
|
+
GEM
|
|
7
|
+
remote: https://rubygems.org/
|
|
8
|
+
specs:
|
|
9
|
+
activemodel (6.1.6.1)
|
|
10
|
+
activesupport (= 6.1.6.1)
|
|
11
|
+
activerecord (6.1.6.1)
|
|
12
|
+
activemodel (= 6.1.6.1)
|
|
13
|
+
activesupport (= 6.1.6.1)
|
|
14
|
+
activesupport (6.1.6.1)
|
|
15
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
16
|
+
i18n (>= 1.6, < 2)
|
|
17
|
+
minitest (>= 5.1)
|
|
18
|
+
tzinfo (~> 2.0)
|
|
19
|
+
zeitwerk (~> 2.3)
|
|
20
|
+
ast (2.4.2)
|
|
21
|
+
concurrent-ruby (1.1.10)
|
|
22
|
+
diff-lcs (1.5.0)
|
|
23
|
+
i18n (1.12.0)
|
|
24
|
+
concurrent-ruby (~> 1.0)
|
|
25
|
+
json (2.6.2)
|
|
26
|
+
minitest (5.16.2)
|
|
27
|
+
parallel (1.22.1)
|
|
28
|
+
parser (3.1.2.1)
|
|
29
|
+
ast (~> 2.4.1)
|
|
30
|
+
rack (2.2.4)
|
|
31
|
+
rainbow (3.1.1)
|
|
32
|
+
rake (13.0.6)
|
|
33
|
+
regexp_parser (2.5.0)
|
|
34
|
+
rexml (3.2.5)
|
|
35
|
+
rspec (3.11.0)
|
|
36
|
+
rspec-core (~> 3.11.0)
|
|
37
|
+
rspec-expectations (~> 3.11.0)
|
|
38
|
+
rspec-mocks (~> 3.11.0)
|
|
39
|
+
rspec-core (3.11.0)
|
|
40
|
+
rspec-support (~> 3.11.0)
|
|
41
|
+
rspec-expectations (3.11.0)
|
|
42
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
43
|
+
rspec-support (~> 3.11.0)
|
|
44
|
+
rspec-mocks (3.11.1)
|
|
45
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
46
|
+
rspec-support (~> 3.11.0)
|
|
47
|
+
rspec-support (3.11.0)
|
|
48
|
+
rubocop (1.34.1)
|
|
49
|
+
json (~> 2.3)
|
|
50
|
+
parallel (~> 1.10)
|
|
51
|
+
parser (>= 3.1.2.1)
|
|
52
|
+
rainbow (>= 2.2.2, < 4.0)
|
|
53
|
+
regexp_parser (>= 1.8, < 3.0)
|
|
54
|
+
rexml (>= 3.2.5, < 4.0)
|
|
55
|
+
rubocop-ast (>= 1.20.0, < 2.0)
|
|
56
|
+
ruby-progressbar (~> 1.7)
|
|
57
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
|
58
|
+
rubocop-ast (1.21.0)
|
|
59
|
+
parser (>= 3.1.1.0)
|
|
60
|
+
rubocop-performance (1.11.5)
|
|
61
|
+
rubocop (>= 1.7.0, < 2.0)
|
|
62
|
+
rubocop-ast (>= 0.4.0)
|
|
63
|
+
rubocop-rails (2.11.3)
|
|
64
|
+
activesupport (>= 4.2.0)
|
|
65
|
+
rack (>= 1.1)
|
|
66
|
+
rubocop (>= 1.7.0, < 2.0)
|
|
67
|
+
rubocop-rspec (2.4.0)
|
|
68
|
+
rubocop (~> 1.0)
|
|
69
|
+
rubocop-ast (>= 1.1.0)
|
|
70
|
+
ruby-progressbar (1.11.0)
|
|
71
|
+
tzinfo (2.0.5)
|
|
72
|
+
concurrent-ruby (~> 1.0)
|
|
73
|
+
unicode-display_width (2.2.0)
|
|
74
|
+
zeitwerk (2.6.0)
|
|
75
|
+
|
|
76
|
+
PLATFORMS
|
|
77
|
+
x86_64-darwin-20
|
|
78
|
+
|
|
79
|
+
DEPENDENCIES
|
|
80
|
+
activerecord (~> 6.0)
|
|
81
|
+
activesupport (~> 6.0)
|
|
82
|
+
chilean-rutify!
|
|
83
|
+
rake (~> 13.0)
|
|
84
|
+
rspec (~> 3.6)
|
|
85
|
+
rubocop (~> 1.0)
|
|
86
|
+
rubocop-performance (~> 1.11.4)
|
|
87
|
+
rubocop-rails (~> 2.11.3)
|
|
88
|
+
rubocop-rspec (~> 2.4.0)
|
|
89
|
+
|
|
90
|
+
BUNDLED WITH
|
|
91
|
+
2.2.26
|
data/README.md
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
# Chilean::Rutify
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://github.com/mihailpozarski/chilean-rutify/actions?query=workflow%3Areviewdog+event%3Apush+branch%3Amain)
|
|
4
|
+
[](https://github.com/mihailpozarski/chilean-rutify/actions?query=workflow%3Arspec+event%3Apush+branch%3Amain)
|
|
5
|
+
|
|
6
|
+
Chilean Rutify is a Ruby on Rails gem that makes rut validations and manipulation easy
|
|
4
7
|
|
|
5
8
|
## Installation
|
|
6
9
|
|
|
@@ -33,11 +36,15 @@ You can use the available utility methods directly form the module:
|
|
|
33
36
|
# => true
|
|
34
37
|
Chilean::Rutify.valid_rut_verifier?(rut)
|
|
35
38
|
# => true
|
|
39
|
+
Chilean::Rutify.valid_rut_values?(rut)
|
|
40
|
+
# => true
|
|
36
41
|
rut = "36408368"
|
|
37
42
|
Chilean::Rutify.get_verifier(rut)
|
|
38
43
|
# => "8"
|
|
39
44
|
```
|
|
40
45
|
|
|
46
|
+
### Validator
|
|
47
|
+
|
|
41
48
|
You can also use the available validator as any other custom Rails validator:
|
|
42
49
|
|
|
43
50
|
```ruby
|
|
@@ -46,6 +53,29 @@ class Person < ActiveRecord::Base
|
|
|
46
53
|
end
|
|
47
54
|
```
|
|
48
55
|
|
|
56
|
+
### Concern
|
|
57
|
+
Or include the new Rutifiable concern (it asumes you created a `rut` column):
|
|
58
|
+
|
|
59
|
+
```ruby
|
|
60
|
+
class Person < ActiveRecord::Base
|
|
61
|
+
includes Chilean::Rutifiable
|
|
62
|
+
self.rut_format = :classic #(optional) options: [:classic, :normalized, :nil] (nil = no override, default: :classic)
|
|
63
|
+
end
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
the last one is equivalent to:
|
|
67
|
+
|
|
68
|
+
```ruby
|
|
69
|
+
class Person < ActiveRecord::Base
|
|
70
|
+
validates :rut, presence: true, uniqueness: { case_sensitive: false }, rut: true
|
|
71
|
+
|
|
72
|
+
def rut=(value)
|
|
73
|
+
value = Chilean::Rutify.format_rut(value)
|
|
74
|
+
super(value)
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
```
|
|
78
|
+
|
|
49
79
|
## Development
|
|
50
80
|
|
|
51
81
|
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.
|
data/_config.yml
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
theme: jekyll-theme-minimal
|
data/bin/console
CHANGED
data/chilean-rutify.gemspec
CHANGED
|
@@ -12,10 +12,11 @@ Gem::Specification.new do |spec|
|
|
|
12
12
|
spec.description = "A useful chilean rut validator and formater for Rails"
|
|
13
13
|
spec.homepage = "https://github.com/mihailpozarski/chilean-rutify"
|
|
14
14
|
spec.license = "MIT"
|
|
15
|
-
spec.required_ruby_version = Gem::Requirement.new(">= 2.
|
|
15
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
|
|
16
16
|
|
|
17
17
|
spec.metadata["homepage_uri"] = spec.homepage
|
|
18
18
|
spec.metadata["source_code_uri"] = "https://github.com/mihailpozarski/chilean-rutify"
|
|
19
|
+
spec.metadata["rubygems_mfa_required"] = "true"
|
|
19
20
|
|
|
20
21
|
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
|
21
22
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
|
@@ -23,4 +24,13 @@ Gem::Specification.new do |spec|
|
|
|
23
24
|
spec.bindir = "exe"
|
|
24
25
|
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
|
25
26
|
spec.require_paths = ["lib"]
|
|
27
|
+
|
|
28
|
+
spec.add_development_dependency "activerecord", "~> 6.0"
|
|
29
|
+
spec.add_development_dependency "activesupport", "~> 6.0"
|
|
30
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
|
31
|
+
spec.add_development_dependency "rspec", "~> 3.6"
|
|
32
|
+
spec.add_development_dependency "rubocop", "~> 1.0"
|
|
33
|
+
spec.add_development_dependency "rubocop-performance", "~> 1.11.4"
|
|
34
|
+
spec.add_development_dependency "rubocop-rails", "~> 2.11.3"
|
|
35
|
+
spec.add_development_dependency "rubocop-rspec", "~> 2.4.0"
|
|
26
36
|
end
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
# Validates that the given string has the correct rut syntax
|
|
1
|
+
# frozen_string_literal: true
|
|
3
2
|
|
|
3
|
+
# Validates that the given string has the correct rut syntax
|
|
4
4
|
class RutValidator < ActiveModel::EachValidator
|
|
5
5
|
def validate_each(record, attribute, value)
|
|
6
|
-
if value.
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
end
|
|
6
|
+
return if value.blank?
|
|
7
|
+
return if Chilean::Rutify.valid_rut?(value)
|
|
8
|
+
|
|
9
|
+
record.errors.add attribute, (options[:message] || "is not a valid rut")
|
|
11
10
|
end
|
|
12
11
|
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Chilean
|
|
4
|
+
# Handles rut validation and formating on models (asumes rut column on model)
|
|
5
|
+
#
|
|
6
|
+
# Options:
|
|
7
|
+
#
|
|
8
|
+
# - :rut_format - The rut setter format, can be [:classic, :normalized, :nil], defaults to `:classic`.
|
|
9
|
+
module Rutifiable
|
|
10
|
+
# TODO: Make Rspec tests
|
|
11
|
+
extend ActiveSupport::Concern
|
|
12
|
+
|
|
13
|
+
included do
|
|
14
|
+
class_attribute :rut_format
|
|
15
|
+
self.rut_format = :classic
|
|
16
|
+
|
|
17
|
+
# Validations
|
|
18
|
+
validates :rut, presence: true, uniqueness: { case_sensitive: false }, rut: true
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# Override rails setter for rut column
|
|
22
|
+
def rut=(value)
|
|
23
|
+
value = Chilean::Rutify.format_rut(value) if rut_format == :classic
|
|
24
|
+
value = Chilean::Rutify.normalize_rut(value) if rut_format == :normalized
|
|
25
|
+
super(value)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
data/lib/chilean/rutify.rb
CHANGED
|
@@ -3,85 +3,110 @@
|
|
|
3
3
|
require_relative "rutify/version"
|
|
4
4
|
require_relative "rutify/rut_validator"
|
|
5
5
|
require_relative "rutify/errors"
|
|
6
|
+
require_relative "rutify/rutifiable"
|
|
6
7
|
|
|
7
8
|
module Chilean
|
|
8
9
|
# Chilean rut utils module
|
|
9
10
|
module Rutify
|
|
10
11
|
# checks if the passed value is valid as a rut character
|
|
11
|
-
def valid_rut_value?(
|
|
12
|
-
[
|
|
12
|
+
def valid_rut_value?(value)
|
|
13
|
+
["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "k", "K", ".", "-"].include?(value.to_s)
|
|
13
14
|
end
|
|
14
15
|
|
|
15
16
|
# returns the rut verifier value
|
|
16
|
-
def get_verifier(
|
|
17
|
+
def get_verifier(raw_rut)
|
|
18
|
+
rut = stringify_rut(raw_rut)
|
|
19
|
+
return unless rut.present? && valid_rut_values?(rut)
|
|
20
|
+
|
|
17
21
|
sum = 0
|
|
18
22
|
mul = 2
|
|
19
23
|
|
|
20
|
-
rut.
|
|
24
|
+
rut.reverse.chars.each do |i|
|
|
21
25
|
sum += i.to_i * mul
|
|
22
26
|
mul = mul == 7 ? 2 : mul + 1
|
|
23
27
|
end
|
|
24
28
|
|
|
25
29
|
res = sum % 11
|
|
26
30
|
|
|
27
|
-
|
|
31
|
+
translate_verifier_result(res)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# translate the result of the rut calculations
|
|
35
|
+
def translate_verifier_result(result)
|
|
36
|
+
case result
|
|
28
37
|
when 1
|
|
29
38
|
"K"
|
|
30
39
|
when 0
|
|
31
40
|
"0"
|
|
32
41
|
else
|
|
33
|
-
(11 -
|
|
42
|
+
(11 - result).to_s
|
|
34
43
|
end
|
|
35
44
|
end
|
|
36
45
|
|
|
37
46
|
# checks if the passed rut has a proper verifier value
|
|
38
47
|
def valid_rut_verifier?(raw_rut)
|
|
39
48
|
rut = normalize_rut(raw_rut)
|
|
40
|
-
return false
|
|
49
|
+
return false unless rut.present? && valid_rut_values?(rut)
|
|
41
50
|
|
|
42
51
|
r = rut[0..(rut.size - 2)]
|
|
43
52
|
get_verifier(r) == rut[-1]
|
|
44
53
|
end
|
|
45
54
|
|
|
46
55
|
# returns the rut value without any sepecial caracter and upcased
|
|
47
|
-
def normalize_rut(
|
|
48
|
-
|
|
56
|
+
def normalize_rut(raw_rut)
|
|
57
|
+
rut = stringify_rut(raw_rut)
|
|
58
|
+
return unless rut.present? && valid_rut_values?(rut)
|
|
49
59
|
|
|
50
|
-
rut.delete
|
|
51
|
-
rut.delete
|
|
60
|
+
rut = rut.delete "."
|
|
61
|
+
rut = rut.delete "-"
|
|
52
62
|
rut.upcase
|
|
53
63
|
end
|
|
54
64
|
|
|
55
65
|
# returns the rut value with the chilean format
|
|
56
66
|
def format_rut(raw_rut)
|
|
57
67
|
rut = normalize_rut(raw_rut)
|
|
58
|
-
return
|
|
68
|
+
return unless rut.present? && valid_rut_values?(rut)
|
|
59
69
|
|
|
60
70
|
verifier = rut[-1]
|
|
61
71
|
temp_rut = rut[0..-2]
|
|
62
72
|
init_rut = ""
|
|
63
73
|
|
|
64
74
|
while temp_rut.length > 3
|
|
65
|
-
init_rut = "
|
|
75
|
+
init_rut = ".#{temp_rut[(temp_rut.size - 3)..temp_rut.size]}#{init_rut}"
|
|
66
76
|
temp_rut = temp_rut[0..-4]
|
|
67
77
|
end
|
|
68
78
|
|
|
69
|
-
|
|
70
|
-
rut.upcase
|
|
79
|
+
"#{temp_rut}#{init_rut}-#{verifier}".upcase
|
|
71
80
|
end
|
|
72
81
|
|
|
73
82
|
# checks if the passed rut is valid
|
|
74
83
|
def valid_rut?(raw_rut)
|
|
75
84
|
rut = normalize_rut(raw_rut)
|
|
76
|
-
return false
|
|
85
|
+
return false unless rut.present? && valid_rut_values?(rut)
|
|
86
|
+
|
|
87
|
+
valid_rut_verifier?(rut)
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
# checks if all the rut values are valid
|
|
91
|
+
def valid_rut_values?(raw_rut)
|
|
92
|
+
rut = stringify_rut(raw_rut)
|
|
93
|
+
return false unless rut.present?
|
|
77
94
|
|
|
78
|
-
rut.
|
|
95
|
+
rut.chars.each do |i|
|
|
79
96
|
return false unless valid_rut_value?(i)
|
|
80
97
|
end
|
|
81
98
|
|
|
82
|
-
|
|
99
|
+
true
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
# checks rut minimum requirements and transform value to string if posible
|
|
103
|
+
def stringify_rut(raw_rut)
|
|
104
|
+
return if raw_rut.nil? || (!raw_rut.is_a?(String) && !raw_rut.is_a?(Integer))
|
|
105
|
+
|
|
106
|
+
raw_rut.to_s
|
|
83
107
|
end
|
|
84
108
|
|
|
85
|
-
module_function :normalize_rut, :format_rut, :valid_rut_value?, :get_verifier, :valid_rut?, :valid_rut_verifier
|
|
109
|
+
module_function :normalize_rut, :format_rut, :valid_rut_value?, :get_verifier, :valid_rut?, :valid_rut_verifier?,
|
|
110
|
+
:valid_rut_values?, :stringify_rut, :translate_verifier_result
|
|
86
111
|
end
|
|
87
112
|
end
|
metadata
CHANGED
|
@@ -1,15 +1,127 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: chilean-rutify
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 1.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Mihail Pozarski
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
12
|
-
dependencies:
|
|
11
|
+
date: 2022-08-11 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: activerecord
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '6.0'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '6.0'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: activesupport
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '6.0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '6.0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rake
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '13.0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '13.0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: rspec
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '3.6'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '3.6'
|
|
69
|
+
- !ruby/object:Gem::Dependency
|
|
70
|
+
name: rubocop
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - "~>"
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '1.0'
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - "~>"
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '1.0'
|
|
83
|
+
- !ruby/object:Gem::Dependency
|
|
84
|
+
name: rubocop-performance
|
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
|
86
|
+
requirements:
|
|
87
|
+
- - "~>"
|
|
88
|
+
- !ruby/object:Gem::Version
|
|
89
|
+
version: 1.11.4
|
|
90
|
+
type: :development
|
|
91
|
+
prerelease: false
|
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
+
requirements:
|
|
94
|
+
- - "~>"
|
|
95
|
+
- !ruby/object:Gem::Version
|
|
96
|
+
version: 1.11.4
|
|
97
|
+
- !ruby/object:Gem::Dependency
|
|
98
|
+
name: rubocop-rails
|
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
|
100
|
+
requirements:
|
|
101
|
+
- - "~>"
|
|
102
|
+
- !ruby/object:Gem::Version
|
|
103
|
+
version: 2.11.3
|
|
104
|
+
type: :development
|
|
105
|
+
prerelease: false
|
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
107
|
+
requirements:
|
|
108
|
+
- - "~>"
|
|
109
|
+
- !ruby/object:Gem::Version
|
|
110
|
+
version: 2.11.3
|
|
111
|
+
- !ruby/object:Gem::Dependency
|
|
112
|
+
name: rubocop-rspec
|
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
|
114
|
+
requirements:
|
|
115
|
+
- - "~>"
|
|
116
|
+
- !ruby/object:Gem::Version
|
|
117
|
+
version: 2.4.0
|
|
118
|
+
type: :development
|
|
119
|
+
prerelease: false
|
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
121
|
+
requirements:
|
|
122
|
+
- - "~>"
|
|
123
|
+
- !ruby/object:Gem::Version
|
|
124
|
+
version: 2.4.0
|
|
13
125
|
description: A useful chilean rut validator and formater for Rails
|
|
14
126
|
email:
|
|
15
127
|
- mihailpozarski@outlook.com
|
|
@@ -17,20 +129,27 @@ executables: []
|
|
|
17
129
|
extensions: []
|
|
18
130
|
extra_rdoc_files: []
|
|
19
131
|
files:
|
|
132
|
+
- ".github/ISSUE_TEMPLATE/bug_report.md"
|
|
133
|
+
- ".github/ISSUE_TEMPLATE/feature_request.md"
|
|
134
|
+
- ".github/workflows/reviewdog.yml"
|
|
135
|
+
- ".github/workflows/rspec.yml"
|
|
20
136
|
- ".gitignore"
|
|
21
137
|
- ".rspec"
|
|
22
138
|
- ".rubocop.yml"
|
|
23
139
|
- CODE_OF_CONDUCT.md
|
|
24
140
|
- Gemfile
|
|
141
|
+
- Gemfile.lock
|
|
25
142
|
- LICENSE.txt
|
|
26
143
|
- README.md
|
|
27
144
|
- Rakefile
|
|
145
|
+
- _config.yml
|
|
28
146
|
- bin/console
|
|
29
147
|
- bin/setup
|
|
30
148
|
- chilean-rutify.gemspec
|
|
31
149
|
- lib/chilean/rutify.rb
|
|
32
150
|
- lib/chilean/rutify/errors.rb
|
|
33
151
|
- lib/chilean/rutify/rut_validator.rb
|
|
152
|
+
- lib/chilean/rutify/rutifiable.rb
|
|
34
153
|
- lib/chilean/rutify/version.rb
|
|
35
154
|
homepage: https://github.com/mihailpozarski/chilean-rutify
|
|
36
155
|
licenses:
|
|
@@ -38,7 +157,8 @@ licenses:
|
|
|
38
157
|
metadata:
|
|
39
158
|
homepage_uri: https://github.com/mihailpozarski/chilean-rutify
|
|
40
159
|
source_code_uri: https://github.com/mihailpozarski/chilean-rutify
|
|
41
|
-
|
|
160
|
+
rubygems_mfa_required: 'true'
|
|
161
|
+
post_install_message:
|
|
42
162
|
rdoc_options: []
|
|
43
163
|
require_paths:
|
|
44
164
|
- lib
|
|
@@ -46,15 +166,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
46
166
|
requirements:
|
|
47
167
|
- - ">="
|
|
48
168
|
- !ruby/object:Gem::Version
|
|
49
|
-
version: 2.
|
|
169
|
+
version: 2.5.0
|
|
50
170
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
51
171
|
requirements:
|
|
52
172
|
- - ">="
|
|
53
173
|
- !ruby/object:Gem::Version
|
|
54
174
|
version: '0'
|
|
55
175
|
requirements: []
|
|
56
|
-
rubygems_version: 3.
|
|
57
|
-
signing_key:
|
|
176
|
+
rubygems_version: 3.1.4
|
|
177
|
+
signing_key:
|
|
58
178
|
specification_version: 4
|
|
59
179
|
summary: Rails chilean rut validator formater
|
|
60
180
|
test_files: []
|