Class: WireClient::CountrySubdivisionValidator

Inherits:
BaseValidator
  • Object
show all
Defined in:
lib/wire_client/base/validators.rb

Instance Method Summary collapse

Methods inherited from BaseValidator

#extract_field_name_value

Instance Method Details

#validate(record) ⇒ Object



50
51
52
53
54
55
56
57
58
59
# File 'lib/wire_client/base/validators.rb', line 50

def validate(record)
  field_name, value = extract_field_name_value(record)
  country = record.send(options[:country] || :country).to_s

  if country == 'US'
    unless US_STATES.key?(value) || US_STATES.value?(value)
      record.errors.add(field_name, :invalid, message: options[:message])
    end
  end
end