demarches-normaliennes/app/models/concerns/email_sanitizable_concern.rb

17 lines
379 B
Ruby
Raw Normal View History

module EmailSanitizableConcern
extend ActiveSupport::Concern
def sanitize_email(attribute)
value_to_sanitize = self.send(attribute)
if value_to_sanitize.present?
self[attribute] = EmailSanitizer.sanitize(value_to_sanitize)
end
end
class EmailSanitizer
def self.sanitize(value)
value.gsub(/[[:space:]]/, ' ').strip.downcase
end
end
end