run_cl 1.2.0 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/README.md +10 -0
- data/lib/run_cl.rb +11 -13
- data/lib/run_cl/run.rb +14 -4
- data/lib/run_cl/run_validator.rb +1 -1
- data/lib/run_cl/uniq_run_validator.rb +13 -2
- data/lib/run_cl/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b3b2acf238e7f70d7ccd620a89b0442d41dcbe9f
|
4
|
+
data.tar.gz: b81bb124df655014b996bda9ec506c0505ecf016
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ddc46964bdcc71f716c79a1a4da2deeced75a9f301c1af606ed36614bc4561aff080173e437825d8cd5ba19018cec1e826fb93762a4ca633b6bd16a666f98e02
|
7
|
+
data.tar.gz: 0537a47a9377a4e5620813bbccceb99b47d7a36d1102895529659013069daa0e74c8d0cb211de7d9e680dd8a3d5a6dd1f4be9c05bd5c2c92e26f619f6d1f2ff1
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -82,11 +82,21 @@ If you need to format a RUN:
|
|
82
82
|
Run.format('111111111')
|
83
83
|
====>> 11.111.111-1
|
84
84
|
|
85
|
+
, or remove the verifying digit:
|
86
|
+
|
87
|
+
Run.format('111111111', false)
|
88
|
+
====>> 11.111.111
|
89
|
+
|
85
90
|
If you need to remove a RUN format:
|
86
91
|
|
87
92
|
Run.remove_format('11.111.111-1')
|
88
93
|
====>> 111111111
|
89
94
|
|
95
|
+
, or remove the verifying digit:
|
96
|
+
|
97
|
+
Run.remove_format('11.111.111-1', false)
|
98
|
+
====>> 11111111
|
99
|
+
|
90
100
|
## Assumptions
|
91
101
|
|
92
102
|
You are saving the RUN as a string, and that is keeping raw (without dots and dashes).
|
data/lib/run_cl.rb
CHANGED
@@ -15,23 +15,21 @@ module RunCl
|
|
15
15
|
module ClassMethods
|
16
16
|
# include InstanceMethods
|
17
17
|
def has_run_cl(name, options = {})
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
18
|
+
run = options.delete(:run)
|
19
|
+
uniq_run = options.delete(:uniq_run)
|
20
|
+
skip_db_format_clear = options.delete(:skip_db_format_clear)
|
21
|
+
|
22
|
+
if run.nil? or run
|
23
|
+
validates name, options.merge({run: true})
|
24
24
|
end
|
25
25
|
|
26
|
-
if
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
validates name, uniq_run: true
|
31
|
-
end
|
26
|
+
if uniq_run.class == Hash and uniq_run.keys.any?
|
27
|
+
validates name, options.merge({uniq_run: uniq_run})
|
28
|
+
elsif uniq_run.nil? or uniq_run == true
|
29
|
+
validates name, options.merge({uniq_run: true})
|
32
30
|
end
|
33
31
|
|
34
|
-
if
|
32
|
+
if skip_db_format_clear.nil? or skip_db_format_clear == false
|
35
33
|
before_validation "make_#{name}_format!"
|
36
34
|
|
37
35
|
define_method "make_#{name}_format!" do
|
data/lib/run_cl/run.rb
CHANGED
@@ -2,7 +2,7 @@ module Run
|
|
2
2
|
extend self
|
3
3
|
|
4
4
|
# Formatea un run
|
5
|
-
def self.format run
|
5
|
+
def self.format run, digit=false
|
6
6
|
return nil if run.nil?
|
7
7
|
pos = 0
|
8
8
|
run.reverse
|
@@ -17,13 +17,23 @@ module Run
|
|
17
17
|
end
|
18
18
|
pos += 1
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
|
+
if digit
|
22
|
+
reverse.reverse[0..-3]
|
23
|
+
else
|
24
|
+
reverse.reverse
|
25
|
+
end
|
21
26
|
end
|
22
27
|
|
23
28
|
# Quita el formato de un run
|
24
|
-
def self.remove_format run
|
29
|
+
def self.remove_format run, digit=false
|
25
30
|
return nil if run.nil?
|
26
|
-
|
31
|
+
|
32
|
+
if digit
|
33
|
+
run.gsub("-", "").gsub(".", "")[0..-3]
|
34
|
+
else
|
35
|
+
run.gsub("-", "").gsub(".", "")
|
36
|
+
end
|
27
37
|
end
|
28
38
|
|
29
39
|
# Generar un run valido segun reglas chilenas y que ademas es unico para el modelo entregado
|
data/lib/run_cl/run_validator.rb
CHANGED
@@ -4,14 +4,25 @@ class UniqRunValidator < ActiveModel::Validator
|
|
4
4
|
def validate record
|
5
5
|
options[:attributes].each do |attribute|
|
6
6
|
run = Run.remove_format record.send(attribute)
|
7
|
+
|
8
|
+
matchers = []
|
7
9
|
if record.new_record?
|
8
|
-
|
10
|
+
matchers = record.class.where(attribute => run)
|
9
11
|
else
|
10
|
-
|
12
|
+
matchers = record.class.where('? = ? AND id != ?', attribute, run, record.id)
|
13
|
+
end
|
14
|
+
|
15
|
+
if options[:scope]
|
16
|
+
matchers = matchers.where(options[:scope] => record.send(options[:scope]))
|
11
17
|
end
|
18
|
+
|
19
|
+
matchers.any?
|
20
|
+
|
21
|
+
record.errors[attribute.to_sym] << 'ya está en uso!!!' if matchers.any?
|
12
22
|
end
|
13
23
|
end
|
14
24
|
|
15
25
|
private
|
26
|
+
# TODO - locales
|
16
27
|
# record.errors[attribute.to_sym] << I18n.t('run.in_use') unless Run.valid? record.send(attribute)
|
17
28
|
end
|
data/lib/run_cl/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: run_cl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mespina
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-09-24 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Formateador/Desformateador, Generador, Validador de Rut Chilenos
|
14
14
|
email:
|
@@ -17,7 +17,7 @@ executables: []
|
|
17
17
|
extensions: []
|
18
18
|
extra_rdoc_files: []
|
19
19
|
files:
|
20
|
-
- .gitignore
|
20
|
+
- ".gitignore"
|
21
21
|
- Gemfile
|
22
22
|
- LICENSE.txt
|
23
23
|
- README.md
|
@@ -37,17 +37,17 @@ require_paths:
|
|
37
37
|
- lib
|
38
38
|
required_ruby_version: !ruby/object:Gem::Requirement
|
39
39
|
requirements:
|
40
|
-
- -
|
40
|
+
- - ">="
|
41
41
|
- !ruby/object:Gem::Version
|
42
42
|
version: '0'
|
43
43
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
requirements: []
|
49
49
|
rubyforge_project:
|
50
|
-
rubygems_version: 2.2.
|
50
|
+
rubygems_version: 2.2.2
|
51
51
|
signing_key:
|
52
52
|
specification_version: 4
|
53
53
|
summary: Rut Chilenos
|