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
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/vat_validator.rb', line 42 def validate_each(record, attribute, value) format_valid = true country_code = [:country_method] ? record.send([:country_method]).to_s : nil unless VatNumber.new(value, country_code).valid? record.errors.add(attribute, [:message]) format_valid = false end if format_valid && [:vies] if [:vies_host] valid = ViesChecker.check(value, [:vies_host]) else valid = ViesChecker.check(value) end unless valid record.errors.add(attribute, [:message]) end end end |