validation_rules 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NzQ2NzQ2ZjEwNWIzNTg3MzJhNzIzOTAxMzM2MzhlZDYxNTE1NzcxOA==
4
+ NjM3M2UyODU5MjM1MjQ0NWQ1NDZiNTQwZjJiMmM1NTE1NzM4ZTBiNQ==
5
5
  data.tar.gz: !binary |-
6
- YmUyZjg3ZWNiYzI5NzIyODM5ZTU2NTRjMDYzOTU0M2JiNTljMzRlZQ==
6
+ MDAxZTdlNDdmYTg3OTMxZDJiYmVlNDAyZWUxYzI0YWExNTlkYjg3Yg==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- YTMzNWU3M2NjYjU5ZDVkZWNlYTM0ZjEyYTBmMWZkZTc1OWRhNjVmYzg1OGRh
10
- MzViMzIyNTY2YjIxY2YwODViZWZlZWEwODAwMzI0N2IxZDJmNjRhNDg5OTcy
11
- OWJkNjc3ODNlMThmNWQwOTYwYWI1OWQzYzM4M2Y3YmI3MDg2NTc=
9
+ MmY4Yzc3M2RkMmE4ZDJhNDQwYWYwMWJhNDdjN2MwNTFhODRkYmRmOTQ1MjMw
10
+ MGYwMjJmZDQ4NTExMjZmYjQxZjc3MTk4MzE3YWZjYTQzNTg5ZTM1ZDU5OTI1
11
+ MTQ3YTg5MDQxY2JjNGM3MTY0NGI4ZmQ4MGI3MDc1YmZkNzM4MTU=
12
12
  data.tar.gz: !binary |-
13
- MjcyMjhmODA3YWM0OTBiZWVhYzQ2ZTE2ZjMxMmViZWZiZTFhMWZkNjQxMDQy
14
- M2VjMDAyYjU1MzFhMTY3MmE2Mzk2NDVlZjgyOTg0ZmVkZDU1Njc3YWMyYjAz
15
- N2QzMTY1MTNhOWE3NjQzNDYxNjkyNTBhNzJlMzRmMTUxYzRkZGM=
13
+ MzlmNjgwOTQwNmNkNDUzZmUzMjFlMTM2NTA1ZTQzMDVjMTRjYzg5ZGRiOWEy
14
+ YWUwMDI5YjM4ZTZhZmM1ZmI3NzZlNDA1NGJlOWZjMjI3MTc0NGVkZjg4MDdm
15
+ YjU4YmNhZjljZTMwZDg1NWNkMzUzMjJmYWM4YWIxMmIzYjA0ODM=
data/README.md CHANGED
@@ -2,6 +2,6 @@
2
2
 
3
3
  A collection of commonly used Ruby validation rules
4
4
 
5
- `gem "validation_rules", "~> 1.0.2"`
5
+ `gem "validation_rules", "~> 1.0.4"`
6
6
 
7
7
  No documentationn yet, use http://rubydoc.info/gems/validation_rules/1.0.2/frames
@@ -14,6 +14,8 @@ module ValidationRules
14
14
  NUMERIC_REGEX = /^[0-9]+$/
15
15
  DATE_REGEX = /^((?:[1-9][0-9]*)?[0-9]{4})-(1[0-2]|0[1-9])-(3[0-1]|0[1-9]|[1-2][0-9])$/
16
16
  ISO8601_REGEX = /^(-?(?:[1-9][0-9]*)?[0-9]{4})-(1[0-2]|0[1-9])-(3[0-1]|0[1-9]|[1-2][0-9])(T(2[0-3]|[0-1][0-9]):([0-5][0-9]):([0-5][0-9])(\.[0-9]+)?(Z|[+-](?:2[0-3]|[0-1][0-9]):[0-5][0-9])?)?$/
17
+ IP_REGEX = /^(\d|[1-9]\d|1\d\d|2([0-4]\d|5[0-5]))\.(\d|[1-9]\d|1\d\d|2([0-4]\d|5[0-5]))\.(\d|[1-9]\d|1\d\d|2([0-4]\d|5[0-5]))\.(\d|[1-9]\d|1\d\d|2([0-4]\d|5[0-5]))$/
18
+ UUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i
17
19
 
18
20
  def self.alpha(value)
19
21
  value =~ ALPHA_REGEX
@@ -161,4 +163,12 @@ module ValidationRules
161
163
  false
162
164
  end
163
165
  end
166
+
167
+ def self.ip_address(value)
168
+ value =~ IP_REGEX
169
+ end
170
+
171
+ def self.uuid(value)
172
+ value =~ UUID_REGEX
173
+ end
164
174
  end
@@ -1,3 +1,3 @@
1
1
  module ValidationRules
2
- VERSION = '1.0.3'
2
+ VERSION = '1.0.4'
3
3
  end
@@ -403,4 +403,28 @@ describe ValidationRules do
403
403
  subject.url('example.com/some path').should be_false
404
404
  end
405
405
  end
406
+
407
+ describe '.ip_address' do
408
+ it 'allows valid IP addresses' do
409
+ subject.ip_address('1.1.1.1').should be_true
410
+ subject.ip_address('255.255.255.255').should be_true
411
+ end
412
+
413
+ it 'rejects invalud IP addresses' do
414
+ subject.ip_address('localhost').should be_false
415
+ subject.ip_address('a.b.c.d').should be_false
416
+ subject.ip_address('255.255.255.256').should be_false
417
+ end
418
+ end
419
+
420
+ describe '.uuid' do
421
+ it 'allows valid UUIDs' do
422
+ subject.uuid('01234567-9ABC-DEF0-1234-56789ABCDEF0').should be_true
423
+ end
424
+
425
+ it 'rejects invalid UUIDs' do
426
+ subject.uuid('invalid').should be_false
427
+ subject.uuid('ABCD-EFG-HIJ-KLM-NOP').should be_false
428
+ end
429
+ end
406
430
  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.3
4
+ version: 1.0.4
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-18 00:00:00.000000000 Z
11
+ date: 2013-04-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec