Class: KBS::DSL::PatternEvaluator
- Inherits:
-
Object
- Object
- KBS::DSL::PatternEvaluator
show all
- Defined in:
- lib/kbs/dsl/pattern_evaluator.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of PatternEvaluator.
8
9
10
|
# File 'lib/kbs/dsl/pattern_evaluator.rb', line 8
def initialize
@pattern = {}
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/kbs/dsl/pattern_evaluator.rb', line 12
def method_missing(method, *args, &block)
if args.empty? && !block_given?
Variable.new(method)
elsif args.length == 1 && !block_given?
@pattern[method] = args.first
elsif block_given?
@pattern[method] = block
else
super
end
end
|
Instance Attribute Details
#pattern ⇒ Object
Returns the value of attribute pattern.
6
7
8
|
# File 'lib/kbs/dsl/pattern_evaluator.rb', line 6
def pattern
@pattern
end
|
Instance Method Details
#!=(value) ⇒ Object
44
45
46
|
# File 'lib/kbs/dsl/pattern_evaluator.rb', line 44
def !=(value)
->(v) { v != value }
end
|
#<(value) ⇒ Object
28
29
30
|
# File 'lib/kbs/dsl/pattern_evaluator.rb', line 28
def <(value)
->(v) { v < value }
end
|
#<=(value) ⇒ Object
36
37
38
|
# File 'lib/kbs/dsl/pattern_evaluator.rb', line 36
def <=(value)
->(v) { v <= value }
end
|
#==(value) ⇒ Object
40
41
42
|
# File 'lib/kbs/dsl/pattern_evaluator.rb', line 40
def ==(value)
value
end
|
#>(value) ⇒ Object
24
25
26
|
# File 'lib/kbs/dsl/pattern_evaluator.rb', line 24
def >(value)
->(v) { v > value }
end
|
#>=(value) ⇒ Object
32
33
34
|
# File 'lib/kbs/dsl/pattern_evaluator.rb', line 32
def >=(value)
->(v) { v >= value }
end
|
#all(*conditions) ⇒ Object
64
65
66
|
# File 'lib/kbs/dsl/pattern_evaluator.rb', line 64
def all(*conditions)
->(v) { conditions.all? { |c| c.is_a?(Proc) ? c.call(v) : c == v } }
end
|
#any(*values) ⇒ Object
60
61
62
|
# File 'lib/kbs/dsl/pattern_evaluator.rb', line 60
def any(*values)
->(v) { values.include?(v) }
end
|
#between(min, max) ⇒ Object
48
49
50
|
# File 'lib/kbs/dsl/pattern_evaluator.rb', line 48
def between(min, max)
->(v) { v >= min && v <= max }
end
|
#in(collection) ⇒ Object
52
53
54
|
# File 'lib/kbs/dsl/pattern_evaluator.rb', line 52
def in(collection)
->(v) { collection.include?(v) }
end
|
#matches(pattern) ⇒ Object
56
57
58
|
# File 'lib/kbs/dsl/pattern_evaluator.rb', line 56
def matches(pattern)
->(v) { v.match?(pattern) }
end
|