15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/explicit/type/string.rb', line 15
def validate(value)
return error_i18n("string") if !value.is_a?(::String)
value = value.strip if strip
value = value.downcase if downcase
if empty == false && value.empty?
return error_i18n("empty")
end
if min_length && value.length < min_length
return error_i18n("min_length", min_length:)
end
if max_length && value.length > max_length
return error_i18n("max_length", max_length:)
end
if format && !format.match?(value)
return error_i18n("format", regex: format.inspect)
end
[ :ok, value ]
end
|