run_cl 1.0.12 → 1.0.14

Sign up to get free protection for your applications and to get access to all the features.
data/lib/run_cl.rb CHANGED
@@ -1,4 +1,8 @@
1
1
  # encoding: utf-8
2
+
3
+ require 'run_cl/run_validator'
4
+
5
+
2
6
  module RunCl
3
7
  module Run
4
8
  extend self
@@ -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
@@ -1,3 +1,3 @@
1
1
  module RunCl
2
- VERSION = "1.0.12"
2
+ VERSION = "1.0.14"
3
3
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 0
8
- - 12
9
- version: 1.0.12
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