Module: Vldt::String
Instance Method Summary collapse
-
#length(value) ⇒ Object
Validate, that a string is of the required length.
-
#length_between(min, max) ⇒ Object
Validate that the length of a string is in a given range.
-
#length_greater_than(min) ⇒ Object
Validate that the length of a string is greater than a minimum.
-
#length_less_than(max) ⇒ Object
Validate that the length of a string is less than a maximum.
-
#match(pattern) ⇒ Object
Validates that object matches (
===
) a pattern. -
#string ⇒ Object
Validate that an object is a string.
Instance Method Details
#length(value) ⇒ Object
Validate, that a string is of the required length.
14 15 16 |
# File 'lib/vldt/string.rb', line 14 def length (value) Predicate.new(:length, { value: value}) { |o| o.length == value } end |
#length_between(min, max) ⇒ Object
Validate that the length of a string is in a given range.
19 20 21 22 23 24 25 |
# File 'lib/vldt/string.rb', line 19 def length_between (min, max) Predicate.new(:length_between, { min: min, max: max }) do |o| length = o.length length >= min && length <= max end end |
#length_greater_than(min) ⇒ Object
Validate that the length of a string is greater than a minimum.
28 29 30 |
# File 'lib/vldt/string.rb', line 28 def length_greater_than (min) Predicate.new(:length_greater_than, { min: min }) { |o| o.length > min } end |
#length_less_than(max) ⇒ Object
Validate that the length of a string is less than a maximum.
33 34 35 |
# File 'lib/vldt/string.rb', line 33 def length_less_than (max) Predicate.new(:length_less_than, { max: max }) { |o| o.length < max } end |