Class: ActiveModel::Validations::ValvatValidator
- Inherits:
-
EachValidator
- Object
- EachValidator
- ActiveModel::Validations::ValvatValidator
- Defined in:
- lib/active_model/validations/valvat_validator.rb
Instance Method Summary collapse
-
#initialize(options) ⇒ ValvatValidator
constructor
A new instance of ValvatValidator.
- #validate_each(record, attribute, value) ⇒ Object
Constructor Details
#initialize(options) ⇒ ValvatValidator
Returns a new instance of ValvatValidator.
10 11 12 13 |
# File 'lib/active_model/validations/valvat_validator.rb', line 10 def initialize() () super end |
Instance Method Details
#validate_each(record, attribute, value) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/active_model/validations/valvat_validator.rb', line 15 def validate_each(record, attribute, value) vat = Valvat(value) iso_country_code = vat.iso_country_code is_valid = if country_does_not_match?(record, iso_country_code) iso_country_code = iso_country_code_of(record) false else vat_valid?(vat) end iso_country_code = 'eu' if iso_country_code.blank? add_error(is_valid, record, attribute, iso_country_code) end |