validation_rules 1.0.4 → 1.0.5
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 +8 -8
- data/README.md +8 -2
- data/lib/validation_rules/validation_rules.rb +7 -1
- data/lib/validation_rules/version.rb +1 -1
- data/spec/validation_rules_spec.rb +9 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NmZmZDQ0ZmZmYTg0ZjkzNjU3NWZhYTllNzM4NjFiOTZhYmEzYzdmZQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YzcwMjMwZGY2YTA2M2ZjYzVhOGY3YTk2YzRmYTdiMWI4YTg4NTdkZQ==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MDQ1Mzc5MmVhMDcwZDQ2ZTFlYjJiYmQ3ZDdmMTZiN2U5MjEyMzk0NzVlYzcy
|
10
|
+
YjhiNzRhNTg4ZDA3NGJmNTk2ZGJlYzIwN2U2MWYyMzY1M2JkN2ZkODZkZWU0
|
11
|
+
ZTZiYzE5MTQ1NTU2YTkxN2JmOWI3YjUxMTZkYjM0YWI3MWE3Nzg=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MWIyZjI1Y2JiMGIzZjhkY2MwNTljY2MyMTcyMGIwYThkODNhZmY0ZTNmYmJk
|
14
|
+
MGU0YTJkNTdhNzcxZDIwYWJhNWU0YWQxNTlmM2E1NzJjYjM5YjI5OWJhN2Nh
|
15
|
+
NDcwODk0OGRjNTBlOWI3NDFmMGEwN2FiZjg2MzEwN2RlNDcwNjE=
|
data/README.md
CHANGED
@@ -2,6 +2,12 @@
|
|
2
2
|
|
3
3
|
A collection of commonly used Ruby validation rules
|
4
4
|
|
5
|
-
`gem "validation_rules", "~> 1.0.
|
5
|
+
`gem "validation_rules", "~> 1.0.5"`
|
6
6
|
|
7
|
-
No documentationn yet, use http://rubydoc.info/gems/validation_rules/1.0.
|
7
|
+
No documentationn yet, use http://rubydoc.info/gems/validation_rules/1.0.5/frames
|
8
|
+
|
9
|
+
Change log:
|
10
|
+
|
11
|
+
*1.0.5*
|
12
|
+
- Changes the way numeric works. It no longer only looks for just integers. It now supports floats, decimals and numeric strings.
|
13
|
+
- Added numeric check to numeric_min, numeric_max, positive, negative and range
|
@@ -124,26 +124,32 @@ module ValidationRules
|
|
124
124
|
end
|
125
125
|
|
126
126
|
def self.numeric(value)
|
127
|
-
value =~
|
127
|
+
return true if value =~ /^\d+$/
|
128
|
+
true if Float(value) rescue false
|
128
129
|
end
|
129
130
|
|
130
131
|
def self.numeric_min(value, min)
|
132
|
+
return false unless numeric(value)
|
131
133
|
value.to_f >= min.to_f
|
132
134
|
end
|
133
135
|
|
134
136
|
def self.numeric_max(value, max)
|
137
|
+
return false unless numeric(value)
|
135
138
|
value.to_f <= max.to_f
|
136
139
|
end
|
137
140
|
|
138
141
|
def self.positive(value)
|
142
|
+
return false unless numeric(value)
|
139
143
|
value.to_f > 0
|
140
144
|
end
|
141
145
|
|
142
146
|
def self.negative(value)
|
147
|
+
return false unless numeric(value)
|
143
148
|
value.to_f < 0
|
144
149
|
end
|
145
150
|
|
146
151
|
def self.range(value, min, max)
|
152
|
+
return false unless numeric(value)
|
147
153
|
value.to_f >= min.to_f and value.to_f <= max.to_f
|
148
154
|
end
|
149
155
|
|
@@ -213,9 +213,15 @@ describe ValidationRules do
|
|
213
213
|
|
214
214
|
it 'validates numeric values' do
|
215
215
|
ValidationRules.numeric('123456').should be_true
|
216
|
+
ValidationRules.numeric(123456).should be_true
|
217
|
+
ValidationRules.numeric('10.99').should be_true
|
218
|
+
ValidationRules.numeric(10.99).should be_true
|
219
|
+
ValidationRules.numeric('5.4e-29').should be_true
|
220
|
+
ValidationRules.numeric('12e20').should be_true
|
221
|
+
ValidationRules.numeric('0').should be_true
|
222
|
+
ValidationRules.numeric(0).should be_true
|
216
223
|
|
217
224
|
ValidationRules.numeric('ABCDS').should be_false
|
218
|
-
ValidationRules.numeric('10.99').should be_false
|
219
225
|
ValidationRules.numeric('ab123.99').should be_false
|
220
226
|
end
|
221
227
|
|
@@ -223,6 +229,7 @@ describe ValidationRules do
|
|
223
229
|
ValidationRules.numeric_min('11', '10').should be_true
|
224
230
|
ValidationRules.numeric_min(11, 10).should be_true
|
225
231
|
ValidationRules.numeric_min(11, 11).should be_true
|
232
|
+
ValidationRules.numeric_min(10.99, 10).should be_true
|
226
233
|
|
227
234
|
ValidationRules.numeric_min(40, 50).should be_false
|
228
235
|
end
|
@@ -231,6 +238,7 @@ describe ValidationRules do
|
|
231
238
|
ValidationRules.numeric_max('50', '69').should be_true
|
232
239
|
ValidationRules.numeric_max(50, 69).should be_true
|
233
240
|
ValidationRules.numeric_max(50, 50).should be_true
|
241
|
+
ValidationRules.numeric_max(10.99, 11).should be_true
|
234
242
|
|
235
243
|
ValidationRules.numeric_max(50, 40).should be_false
|
236
244
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: validation_rules
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Gotterer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-04-
|
11
|
+
date: 2013-04-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|