Class: Validatious::Validators::TextContentValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- Validatious::Validators::TextContentValidator
show all
- Defined in:
- lib/validatious/validators/text_content_validator.rb
Overview
Active Model Text Content Validator
Instance Method Summary
collapse
Instance Method Details
#validate_each(record, attribute, value) ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/validatious/validators/text_content_validator.rb', line 6
def validate_each(record, attribute, value)
return if value.nil?
error = false
error = true if value.match(/[A-Z]/).nil?
error = true if value.match(/[\.?!]/).nil?
error = true if value.downcase.count('e') < (value.downcase.gsub(/[^a-z]*/, '').length / 30)
error = true if value.downcase.count(' ') < (value.length / 20)
error = true if value.gsub(/[^a-z]*/, '').length < (value.downcase.gsub(/[^a-z]*/, '').length / 4)
record.errors.add(attribute, :invalid_text_content, options) if error
end
|