Class: VatValidator::VatValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- VatValidator::VatValidator
- Defined in:
- lib/vat_validator.rb
Overview
Classes ——————————————————————–
Instance Method Summary collapse
Instance Method Details
#validate_each(record, attribute, value) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/vat_validator.rb', line 40 def validate_each(record, attribute, value) if [:country_method] country_code = record.send([:country_method]).to_s unless VAT_PATTERNS.has_key?(country_code) && value.to_s =~ VAT_PATTERNS[country_code] record.errors.add(attribute, [:message]) end else unless value =~ VAT_PATTERNS.values.detect { |p| value.to_s =~ p } record.errors.add(attribute, [:message]) end end end |