Module: Vldt::Number

Extended by:
Number
Included in:
Number
Defined in:
lib/vldt/number.rb

Overview

Function for number validation.

Instance Method Summary collapse

Instance Method Details

#between(min, max) ⇒ Object

Validates that a number is in a given range, boundaries included.



30
31
32
# File 'lib/vldt/number.rb', line 30

def between (min, max)
  Predicate.new(:between, { min: min, max: max }) { |o| o >= min && o <= max }
end

#evenObject

Validate, that a number is even.



45
46
47
# File 'lib/vldt/number.rb', line 45

def even
  Predicate.new(:even, {}, &:even?)
end

#greater_than(min) ⇒ Object

Validates that object is greater than a minimum.



10
11
12
# File 'lib/vldt/number.rb', line 10

def greater_than (min)
  Predicate.new(:greater_than, { min: min }) { |o| o > min }
end

#greater_than_or_equal_to(min) ⇒ Object

Validates that the number is greater than or equal to a minimum.



15
16
17
# File 'lib/vldt/number.rb', line 15

def greater_than_or_equal_to (min)
  Predicate.new(:greater_than_or_equal_to, { min: min }) { |o| o >= min }
end

#integerObject

Validate, that object is an integer.



35
36
37
# File 'lib/vldt/number.rb', line 35

def integer
  Predicate.new(:integer, {}) { |o| o.is_a?(Integer) }
end

#less_than(max) ⇒ Object

Validate that a number is less than a maximum.



20
21
22
# File 'lib/vldt/number.rb', line 20

def less_than (max)
  Predicate.new(:less_than, { max: max }) { |o| o < max }
end

#less_than_or_equal_to(max) ⇒ Object

Validates that a number is less than or equal to a maximum.



25
26
27
# File 'lib/vldt/number.rb', line 25

def less_than_or_equal_to (max)
  Predicate.new(:less_than_or_equal_to, { max: max }) { |o| o <= max }
end

#negativeObject

Validate that a number is negative (< 0).



60
61
62
# File 'lib/vldt/number.rb', line 60

def negative
  Predicate.new(:negative, {}) { |o| o < 0 }
end

#not_negativeObject

Validate that a number is not negative (>= 0).



65
66
67
# File 'lib/vldt/number.rb', line 65

def not_negative
  Predicate.new(:not_negative, {}) { |o| o >= 0 }
end

#not_positiveObject

Validate, that a number is not positive (<= 0).



55
56
57
# File 'lib/vldt/number.rb', line 55

def not_positive
  Predicate.new(:not_positive, {}) { |o| o <= 0 }
end

#numberObject

Validate, that object is a number.



5
6
7
# File 'lib/vldt/number.rb', line 5

def number
  Predicate.new(:number, {}) { |o| o.is_a?(Numeric) }
end

#oddObject

Validate, that a number is odd.



40
41
42
# File 'lib/vldt/number.rb', line 40

def odd
  Predicate.new(:odd, {}, &:odd?)
end

#positiveObject

Validate, that a number is positive (> 0).



50
51
52
# File 'lib/vldt/number.rb', line 50

def positive
  Predicate.new(:positive, {}) { |o| o > 0 }
end