valid
Advanced tools
| module Validation | ||
| module Rule | ||
| # Phone rule | ||
| class Phone | ||
| # params can be any of the following: | ||
| # | ||
| # - :format - the phone number format | ||
| # | ||
| # Example: | ||
| # | ||
| # {:format => :america} | ||
| def initialize(params = {:format => :america}) | ||
| @params = params | ||
| end | ||
| # returns the params given in the constructor | ||
| def params | ||
| @params | ||
| end | ||
| # determines if value is valid according to the constructor params | ||
| def valid_value?(value) | ||
| send(@params[:format], value) | ||
| end | ||
| def error_key | ||
| :phone | ||
| end | ||
| protected | ||
| def america(value) | ||
| digits = value.gsub(/\D/, '').split(//) | ||
| digits.length == 10 || digits.length == 11 | ||
| end | ||
| end | ||
| end | ||
| end |
| module Validation | ||
| VERSION = '0.2.1' | ||
| VERSION = '0.3.0' | ||
| end |
+2
-0
| # Validator | ||
| [](http://travis-ci.org/zombor/Validator) | ||
| 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,0 +6,0 @@ |