run_cl 1.0.12 → 1.0.14
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.
- data/lib/run_cl.rb +4 -0
- data/lib/run_cl/run_validator.rb +19 -0
- data/lib/run_cl/version.rb +1 -1
- metadata +3 -2
data/lib/run_cl.rb
CHANGED
@@ -0,0 +1,19 @@
|
|
1
|
+
class RunValidator < ActiveModel::Validator
|
2
|
+
def validate record
|
3
|
+
options[:attributes].each do |attribute|
|
4
|
+
# record.errors[:run] << I18n.t('run.invalid') unless valid_run? record
|
5
|
+
record.errors[attribute.to_sym] << 'no es válido' unless valid_run? record, attribute
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def valid_run? record, attribute
|
12
|
+
if run = record.send(attribute).presence
|
13
|
+
record.send("#{attribute}=", (( run = run.match(/^(\d+)[^\d*](\d+)[^\d*](\d+)[^\d*](\d|k)|(\d+)[^\d*](\d|k)|(\d+k)|(\d+)$/i).to_s ) =~ /\.|\-/ ? run.gsub!(/\.|\-/, '') : run))
|
14
|
+
RunCl::Run.check_run record.send(attribute).chop, record.send(attribute).last
|
15
|
+
else
|
16
|
+
false
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/run_cl/version.rb
CHANGED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 1
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 1.0.
|
8
|
+
- 14
|
9
|
+
version: 1.0.14
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- mespina
|
@@ -59,6 +59,7 @@ files:
|
|
59
59
|
- README.md
|
60
60
|
- Rakefile
|
61
61
|
- lib/run_cl.rb
|
62
|
+
- lib/run_cl/run_validator.rb
|
62
63
|
- lib/run_cl/version.rb
|
63
64
|
- run_cl.gemspec
|
64
65
|
has_rdoc: true
|