Module: Vldt::Array

Extended by:
Array
Included in:
Array
Defined in:
lib/vldt/array.rb

Instance Method Summary collapse

Instance Method Details

#arrayObject

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

#length_greater_than(min) ⇒ Object

Validate that the length of an array is greater than a minimum.



23
24
25
# File 'lib/vldt/array.rb', line 23

def length_greater_than (min)
  Predicate.new(:array_length_greater_than, { min: min }) { |o| o.length > min }
end

#length_less_than(max) ⇒ Object

Validate that the length of an array is less than a maximum.



28
29
30
# File 'lib/vldt/array.rb', line 28

def length_less_than (max)
  Predicate.new(:array_length_less_than, { max: max }) { |o| o.length < max }
end