Class: DataValidator::FormatValidator
- Inherits:
-
BaseValidator
- Object
- BaseValidator
- DataValidator::FormatValidator
- Defined in:
- lib/validations/format.rb
Instance Attribute Summary
Attributes inherited from BaseValidator
#errors, #name, #options, #value
Instance Method Summary collapse
Methods inherited from BaseValidator
Constructor Details
This class inherits a constructor from DataValidator::BaseValidator
Instance Method Details
#check_validity! ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/validations/format.rb', line 5 def check_validity! unless .include?(:with) ^ .include?(:without) # ^ == xor, or "exclusive or" raise ArgumentError, 'Either :with or :without must be supplied (but not both)' end (, :with) (, :without) end |
#validate ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/validations/format.rb', line 13 def validate if regexp = [:with] add_error :invalid if value.to_s !~ regexp elsif regexp = [:without] add_error :invalid if value.to_s =~ regexp end end |