Class: Coradoc::Validation::Rules::Format
- Inherits:
-
Coradoc::Validation::Rule
- Object
- Coradoc::Validation::Rule
- Coradoc::Validation::Rules::Format
- Defined in:
- lib/coradoc/validation.rb
Overview
Format validation with regex
Instance Attribute Summary
Attributes inherited from Coradoc::Validation::Rule
Instance Method Summary collapse
Methods inherited from Coradoc::Validation::Rule
Constructor Details
This class inherits a constructor from Coradoc::Validation::Rule
Instance Method Details
#validate(element, _context = {}) ⇒ Object
275 276 277 278 279 280 281 282 283 284 285 |
# File 'lib/coradoc/validation.rb', line 275 def validate(element, _context = {}) field = [:field] pattern = [:pattern] value = element.send(field) if element.respond_to?(field) return [] if value.nil? return ["#{field} has invalid format"] unless pattern.match?(value.to_s) [] end |