Sha256: 6a2a1724b91b5e9697671c71a483bbc6b01d51060687db97252bdcdf0092cc6f
Contents?: true
Size: 512 Bytes
Versions: 3
Compression:
Stored size: 512 Bytes
Contents
class AreaCodeInvalidValidator < ActiveModel::Validator 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 end
Version data entries
3 entries across 3 versions & 1 rubygems