valid 0.2.1 → 0.3.0

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/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Validator
2
2
 
3
+ [![Build Status](https://secure.travis-ci.org/zombor/Validator.png)](http://travis-ci.org/zombor/Validator)
4
+
3
5
  Validator is a simple ruby validation class. You don't use it directly inside your classes like just about every other ruby validation class out there. I chose to implement it in this way so I didn't automatically pollute the namespace of the objects I wanted to validate.
4
6
 
5
7
  This also solves the problem of validating forms very nicely. Frequently you will have a form that represents many different data objects in your system, and you can pre-validate everything before doing any saving.
@@ -0,0 +1,39 @@
1
+ module Validation
2
+ module Rule
3
+ # Phone rule
4
+ class Phone
5
+ # params can be any of the following:
6
+ #
7
+ # - :format - the phone number format
8
+ #
9
+ # Example:
10
+ #
11
+ # {:format => :america}
12
+ def initialize(params = {:format => :america})
13
+ @params = params
14
+ end
15
+
16
+ # returns the params given in the constructor
17
+ def params
18
+ @params
19
+ end
20
+
21
+ # determines if value is valid according to the constructor params
22
+ def valid_value?(value)
23
+ send(@params[:format], value)
24
+ end
25
+
26
+ def error_key
27
+ :phone
28
+ end
29
+
30
+ protected
31
+
32
+ def america(value)
33
+ digits = value.gsub(/\D/, '').split(//)
34
+
35
+ digits.length == 10 || digits.length == 11
36
+ end
37
+ end
38
+ end
39
+ end
@@ -1,3 +1,3 @@
1
1
  module Validation
2
- VERSION = '0.2.1'
2
+ VERSION = '0.3.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: valid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-17 00:00:00.000000000 Z
12
+ date: 2013-04-29 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description:
15
15
  email:
@@ -23,6 +23,7 @@ files:
23
23
  - lib/validation/rule/matches.rb
24
24
  - lib/validation/rule/not_empty.rb
25
25
  - lib/validation/rule/numeric.rb
26
+ - lib/validation/rule/phone.rb
26
27
  - lib/validation/validator.rb
27
28
  - lib/validation/version.rb
28
29
  - lib/validation.rb