Module: Definition::Dsl::Comparators
- Included in:
- Definition
- Defined in:
- lib/definition/dsl/comparators.rb
Instance Method Summary collapse
-
#Empty ⇒ Object
Example: Empty.
-
#Equal(expected_value) ⇒ Object
Example: Equal(“value”).
-
#GreaterThen(min_value) ⇒ Object
Example: GreaterThen(5).
-
#GreaterThenEqual(min_value) ⇒ Object
Example: GreaterThenEqual(5).
-
#LessThen(max_value) ⇒ Object
Example: LessThen(5).
-
#LessThenEqual(max_value) ⇒ Object
Example: LessThenEqual(5).
-
#MaxSize(max_size) ⇒ Object
Example: MaxSize(5).
-
#MinSize(min_size) ⇒ Object
Example: MinSize(5).
-
#NonEmpty ⇒ Object
Example: NonEmpty.
-
#NonEmptyString ⇒ Object
Example: NonEmptyString.
-
#Regex(regex) ⇒ Object
Example: Regex.
Instance Method Details
#Empty ⇒ Object
Example: Empty
80 81 82 83 84 85 86 87 88 89 |
# File 'lib/definition/dsl/comparators.rb', line 80 def Empty # rubocop:disable Naming/MethodName Types::Lambda.new(:empty) do |value| case value when String, Array, Hash conform_with(value) if value.empty? else value end end end |
#Equal(expected_value) ⇒ Object
Example: Equal(“value”)
72 73 74 75 76 |
# File 'lib/definition/dsl/comparators.rb', line 72 def Equal(expected_value) # rubocop:disable Naming/MethodName Types::Lambda.new(:equal) do |value| conform_with(value) if value == expected_value end end |
#GreaterThen(min_value) ⇒ Object
Example: GreaterThen(5)
40 41 42 43 44 |
# File 'lib/definition/dsl/comparators.rb', line 40 def GreaterThen(min_value) # rubocop:disable Naming/MethodName Types::Lambda.new("greater_then_#{min_value}") do |value| conform_with(value) if value.is_a?(Numeric) && value > min_value end end |
#GreaterThenEqual(min_value) ⇒ Object
Example: GreaterThenEqual(5)
48 49 50 51 52 |
# File 'lib/definition/dsl/comparators.rb', line 48 def GreaterThenEqual(min_value) # rubocop:disable Naming/MethodName Types::Lambda.new("greater_then_equal_#{min_value}") do |value| conform_with(value) if value.is_a?(Numeric) && value >= min_value end end |
#LessThen(max_value) ⇒ Object
Example: LessThen(5)
56 57 58 59 60 |
# File 'lib/definition/dsl/comparators.rb', line 56 def LessThen(max_value) # rubocop:disable Naming/MethodName Types::Lambda.new("less_then_#{max_value}") do |value| conform_with(value) if value.is_a?(Numeric) && value < max_value end end |
#LessThenEqual(max_value) ⇒ Object
Example: LessThenEqual(5)
64 65 66 67 68 |
# File 'lib/definition/dsl/comparators.rb', line 64 def LessThenEqual(max_value) # rubocop:disable Naming/MethodName Types::Lambda.new("less_then_equal_#{max_value}") do |value| conform_with(value) if value.is_a?(Numeric) && value <= max_value end end |
#MaxSize(max_size) ⇒ Object
Example: MaxSize(5)
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/definition/dsl/comparators.rb', line 8 def MaxSize(max_size) # rubocop:disable Naming/MethodName Types::Lambda.new(:max_size) do |value| case value when String, Enumerable conform_with(value) if value.size <= max_size else value end end end |
#MinSize(min_size) ⇒ Object
Example: MinSize(5)
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/definition/dsl/comparators.rb', line 21 def MinSize(min_size) # rubocop:disable Naming/MethodName Types::Lambda.new(:min_size) do |value| case value when String, Enumerable conform_with(value) if value.size >= min_size else value end end end |
#NonEmpty ⇒ Object
Example: NonEmpty
93 94 95 96 97 98 99 100 101 102 |
# File 'lib/definition/dsl/comparators.rb', line 93 def NonEmpty # rubocop:disable Naming/MethodName Types::Lambda.new(:non_empty) do |value| case value when String, Array, Hash conform_with(value) unless value.empty? else value end end end |
#NonEmptyString ⇒ Object
Example: NonEmptyString
34 35 36 |
# File 'lib/definition/dsl/comparators.rb', line 34 def NonEmptyString # rubocop:disable Naming/MethodName Types::And.new(:non_empty_string, Type(String), MinSize(1)) end |
#Regex(regex) ⇒ Object
Example: Regex
106 107 108 109 110 111 112 113 114 115 |
# File 'lib/definition/dsl/comparators.rb', line 106 def Regex(regex) # rubocop:disable Naming/MethodName Types::Lambda.new("regex #{regex.inspect}") do |value| case value when String conform_with(value) unless regex.match(value).nil? else value end end end |