run_cl 1.0.8 → 1.0.9

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.
Files changed (3) hide show
  1. data/lib/run_cl.rb +20 -4
  2. data/lib/run_cl/version.rb +1 -1
  3. metadata +2 -2
data/lib/run_cl.rb CHANGED
@@ -1,7 +1,3 @@
1
- # require '/run_cl/run'
2
- require '/run_cl/run_validator'
3
- require '/run_cl/version'
4
-
5
1
  module RunCl
6
2
  module Run
7
3
  extend self
@@ -90,4 +86,24 @@ module RunCl
90
86
  false
91
87
  end
92
88
  end
89
+
90
+ class RunValidator < ActiveModel::Validator
91
+ def validate record
92
+ options[:attributes].each do |attribute|
93
+ # record.errors[:run] << I18n.t('run.invalid') unless valid_run? record
94
+ record.errors[attribute.to_sym] << 'no es válido' unless valid_run? record, attribute
95
+ end
96
+ end
97
+
98
+ private
99
+
100
+ def valid_run? record, attribute
101
+ if run = record.send(attribute).presence
102
+ 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))
103
+ RunCl::Run.check_run record.send(attribute).chop, record.send(attribute).last
104
+ else
105
+ false
106
+ end
107
+ end
108
+ end
93
109
  end
@@ -1,3 +1,3 @@
1
1
  module RunCl
2
- VERSION = "1.0.8"
2
+ VERSION = "1.0.9"
3
3
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 0
8
- - 8
9
- version: 1.0.8
8
+ - 9
9
+ version: 1.0.9
10
10
  platform: ruby
11
11
  authors:
12
12
  - mespina