Module: Vldt::Array
Instance Method Summary collapse
-
#array ⇒ Object
Validate that an object is an array.
-
#length(value) ⇒ Object
Validate, that an array is of the required length.
-
#length_between(min, max) ⇒ Object
Validate that the length of an array is in a given range.
-
#length_greater_than(min) ⇒ Object
Validate that the length of an array is greater than a minimum.
-
#length_less_than(max) ⇒ Object
Validate that the length of an array is less than a maximum.
Instance Method Details
#array ⇒ Object
Validate that an object is an array.
4 5 6 |
# File 'lib/vldt/array.rb', line 4 def array Predicate.new(:array, {}) { |o| o.is_a?(::Array) } end |
#length(value) ⇒ Object
Validate, that an array is of the required length.
9 10 11 |
# File 'lib/vldt/array.rb', line 9 def length (value) Predicate.new(:array_length, { value: value}) { |o| o.length == value } end |
#length_between(min, max) ⇒ Object
Validate that the length of an array is in a given range.
14 15 16 17 18 19 20 |
# File 'lib/vldt/array.rb', line 14 def length_between (min, max) Predicate.new(:array_length_between, { min: min, max: max }) do |o| length = o.length length >= min && length <= max end end |