znamenica/dneslov

View on GitHub
app/validators/patronymic_validator.rb

Summary

Maintainability
A
0 mins
Test Coverage
F
0%
class PatronymicValidator < ActiveModel::EachValidator
   TABLE = {
      # РУ -ович/-овна/-евич/-евна/-ич/-ыч/-на/-ль/вар-
      ру: /((ич|и́ч|ыч|на|ль)\z|\AВар)/
   }

   def validate_each(record, attribute, value)
      re = TABLE[ record.language_code.to_sym ]
      if re && value !~ re
         record.errors[ attribute ] <<
         I18n.t( 'activerecord.errors.invalid_patronymic' ) ; end ; end ; end