Class: ParanoidStarlight::Validators::NameValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/paranoid_starlight.rb

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/paranoid_starlight.rb', line 22

def validate_each(record, attribute, value)
  fullname = '\p{Letter}+(-\p{Letter}+)*'
  surname = fullname
  short = '\p{Letter}\.'
  unless value =~ /\A(?:#{fullname} ((#{fullname}|#{short}) )*#{surname})\z/
    record.errors[attribute] << (options[:message] || 'is not a name')
  end
end