Class: AreaCodeInvalidValidator
- Inherits:
-
ActiveModel::Validator
- Object
- ActiveModel::Validator
- AreaCodeInvalidValidator
- Defined in:
- lib/extensions/area_code_invalid_validator.rb
Instance Method Summary collapse
Instance Method Details
#validate(record) ⇒ Object
2 3 4 5 6 7 8 |
# File 'lib/extensions/area_code_invalid_validator.rb', line 2 def validate(record) phone_key = @options[:attributes].collect { |x| x if x.to_s.include?('phone') }.compact!.first state_key = @options[:attributes].collect { |x| x if x.to_s.include?('state') }.compact!.first phone_number = record[phone_key].to_s state = record[state_key].to_s record.errors.add(phone_key, "has an invalid area code for state #{state}") if AreaCodeValidator.invalid?(phone_number[0,3], state) end |