Class: Rbdantic::Validators::Types::String
- Inherits:
-
Base
- Object
- Base
- Rbdantic::Validators::Types::String
show all
- Defined in:
- lib/rbdantic/validators/types/string.rb
Constant Summary
collapse
- FORMAT_PATTERNS =
{
email: /\A[^@\s]+@[^@\s]+\z/,
uri: /\A[a-zA-Z][a-zA-Z0-9+.-]*:\/\/[^\s]+\z/,
uuid: /\A[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\z/i
}.freeze
Instance Attribute Summary
Attributes inherited from Base
#constraints
Instance Method Summary
collapse
Methods inherited from Base
#initialize, #validate
Instance Method Details
#coerce(value) ⇒ Object
23
24
25
26
27
28
29
|
# File 'lib/rbdantic/validators/types/string.rb', line 23
def coerce(value)
case value
when ::String then value
when ::Symbol, Numeric, TrueClass, FalseClass then value.to_s
else nil
end
end
|
#expected_type_name ⇒ Object
19
20
21
|
# File 'lib/rbdantic/validators/types/string.rb', line 19
def expected_type_name
"String"
end
|
#matches_type?(value) ⇒ Boolean
15
16
17
|
# File 'lib/rbdantic/validators/types/string.rb', line 15
def matches_type?(value)
value.is_a?(::String)
end
|
#validate_constraints(value, errors, location, strict: false) ⇒ Object
31
32
33
34
35
36
|
# File 'lib/rbdantic/validators/types/string.rb', line 31
def validate_constraints(value, errors, location, strict: false)
validate_length(value, errors, location)
validate_pattern(value, errors, location)
validate_format(value, errors, location)
value
end
|