Module: Vldt::String

Extended by:
String
Included in:
String
Defined in:
lib/vldt/string.rb

Instance Method Summary collapse

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

#match(pattern) ⇒ Object

Validates that object matches (===) a pattern.



9
10
11
# File 'lib/vldt/string.rb', line 9

def match (pattern)
  Predicate.new(:match, pattern: pattern) { |o| pattern === o }
end

#stringObject

Validate that an object is a string.



4
5
6
# File 'lib/vldt/string.rb', line 4

def string
  Predicate.new(:string, {}) { |o| o.is_a?(::String) }
end