Module: Vldt::Number
Overview
Function for number validation.
Instance Method Summary collapse
-
#between(min, max) ⇒ Object
Validates that a number is in a given range, boundaries included.
-
#even ⇒ Object
Validate, that a number is even.
-
#greater_than(min) ⇒ Object
Validates that object is greater than a minimum.
-
#greater_than_or_equal_to(min) ⇒ Object
Validates that the number is greater than or equal to a minimum.
-
#integer ⇒ Object
Validate, that object is an integer.
-
#less_than(max) ⇒ Object
Validate that a number is less than a maximum.
-
#less_than_or_equal_to(max) ⇒ Object
Validates that a number is less than or equal to a maximum.
-
#negative ⇒ Object
Validate that a number is negative (< 0).
-
#not_negative ⇒ Object
Validate that a number is not negative (>= 0).
-
#not_positive ⇒ Object
Validate, that a number is not positive (<= 0).
-
#number ⇒ Object
Validate, that object is a number.
-
#odd ⇒ Object
Validate, that a number is odd.
-
#positive ⇒ Object
Validate, that a number is positive (> 0).
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 |
#even ⇒ Object
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 |
#integer ⇒ Object
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 |
#negative ⇒ Object
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_negative ⇒ Object
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_positive ⇒ Object
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 |
#number ⇒ Object
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 |