Class: LIVR::Rules::String::MaxLength
- Inherits:
-
LIVR::Rule
- Object
- LIVR::Rule
- LIVR::Rules::String::MaxLength
- Defined in:
- lib/livr/rules/string.rb
Instance Method Summary collapse
- #call(value, user_data, field_results) ⇒ Object
-
#initialize(max_length) ⇒ MaxLength
constructor
A new instance of MaxLength.
Constructor Details
#initialize(max_length) ⇒ MaxLength
Returns a new instance of MaxLength.
55 56 57 |
# File 'lib/livr/rules/string.rb', line 55 def initialize(max_length) @max_length = max_length end |
Instance Method Details
#call(value, user_data, field_results) ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'lib/livr/rules/string.rb', line 59 def call(value, user_data, field_results) return if value.in? [nil, ""] return 'FORMAT_ERROR' unless is_primitive(value) return 'TOO_LONG' if value.to_s.length > @max_length field_results << value.to_s return end |