Module: KBS::DSL::ConditionHelpers

Included in:
RuleBuilder
Defined in:
lib/kbs/dsl/condition_helpers.rb

Instance Method Summary collapse

Instance Method Details

#any(*values) ⇒ Object



38
39
40
41
42
43
44
45
46
# File 'lib/kbs/dsl/condition_helpers.rb', line 38

def any(*values)
  if values.empty?
    # Match anything
    ->(v) { true }
  else
    # Match one of the values
    one_of(*values)
  end
end

#between(min, max) ⇒ Object



34
35
36
# File 'lib/kbs/dsl/condition_helpers.rb', line 34

def between(min, max)
  range(min, max)
end

#equals(value) ⇒ Object



14
15
16
# File 'lib/kbs/dsl/condition_helpers.rb', line 14

def equals(value)
  value
end

#greater_than(value) ⇒ Object



10
11
12
# File 'lib/kbs/dsl/condition_helpers.rb', line 10

def greater_than(value)
  ->(v) { v > value }
end

#less_than(value) ⇒ Object



6
7
8
# File 'lib/kbs/dsl/condition_helpers.rb', line 6

def less_than(value)
  ->(v) { v < value }
end

#matches(pattern) ⇒ Object



48
49
50
# File 'lib/kbs/dsl/condition_helpers.rb', line 48

def matches(pattern)
  ->(v) { v.match?(pattern) }
end

#not_equal(value) ⇒ Object



18
19
20
# File 'lib/kbs/dsl/condition_helpers.rb', line 18

def not_equal(value)
  ->(v) { v != value }
end

#one_of(*values) ⇒ Object



22
23
24
# File 'lib/kbs/dsl/condition_helpers.rb', line 22

def one_of(*values)
  ->(v) { values.include?(v) }
end

#range(min_or_range, max = nil) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/kbs/dsl/condition_helpers.rb', line 26

def range(min_or_range, max = nil)
  if min_or_range.is_a?(Range)
    ->(v) { min_or_range.include?(v) }
  else
    ->(v) { v >= min_or_range && v <= max }
  end
end

#satisfies(&block) ⇒ Object



52
53
54
# File 'lib/kbs/dsl/condition_helpers.rb', line 52

def satisfies(&block)
  block
end