class Dugway::ContactFormValidator
Attributes
params[RW]
Public Class Methods
new(params)
click to toggle source
# File lib/dugway/contact_form_validator.rb, line 6 def initialize(params) @params = params end
Public Instance Methods
error_message()
click to toggle source
# File lib/dugway/contact_form_validator.rb, line 10 def error_message if required_fields.any? { |f| params[f].blank? } 'All fields are required' elsif param_does_not_match(:email, email_format) 'Invalid email address' end end
Private Instance Methods
email_format()
click to toggle source
# File lib/dugway/contact_form_validator.rb, line 24 def email_format /^([^@\s]+)@((?:[-a-zA-Z0-9]+\.)+[a-zA-Z]{2,})$/ end
param_does_not_match(param_name, regex)
click to toggle source
# File lib/dugway/contact_form_validator.rb, line 28 def param_does_not_match(param_name, regex) !(params[param_name.to_sym] =~ regex) end
required_fields()
click to toggle source
# File lib/dugway/contact_form_validator.rb, line 20 def required_fields [ :name, :email, :subject, :message ] end