Class: Mushy::Filter
- Inherits:
-
Flux
- Object
- Flux
- Mushy::Filter
show all
- Defined in:
- lib/mushy/fluxs/filter.rb
Instance Attribute Summary
Attributes inherited from Flux
#config, #flow, #id, #masher, #parent_fluxs, #subscribed_to, #type
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Flux
#convert_this_to_an_array, #convert_to_symbolized_hash, #execute, #execute_single_event, #group_these_results, #guard, #ignore_these_results, inherited, #initialize, #join_these_results, #limit_these_results, #merge_these_results, #model_these_results, #outgoing_split_these_results, #shape_these, #sort_these_results, #standardize_these
Constructor Details
This class inherits a constructor from Mushy::Flux
Class Method Details
.details ⇒ Object
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/mushy/fluxs/filter.rb', line 5
def self.details
{
name: 'Filter',
description: 'Filters events based on criteria.',
config: {
equal: {
description: 'Provide key/value pairs that must match in the event.',
shrink: true,
label: 'Equal To',
type: 'keyvalue',
value: {},
},
notequal: {
description: 'Provide key/value pairs that must NOT match in the event.',
shrink: true,
label: 'Not Equal To',
type: 'keyvalue',
value: {},
},
},
}
end
|
Instance Method Details
#equal(a, b) ⇒ Object
42
43
44
45
46
47
48
|
# File 'lib/mushy/fluxs/filter.rb', line 42
def equal a, b
[a, b]
.map { |x| numeric?(x) ? x.to_f : x }
.map { |x| x.to_s.strip.downcase }
.group_by { |x| x }
.count == 1
end
|
#notequal(a, b) ⇒ Object
50
51
52
|
# File 'lib/mushy/fluxs/filter.rb', line 50
def notequal a, b
equal(a, b) == false
end
|
#numeric?(value) ⇒ Boolean
54
55
56
|
# File 'lib/mushy/fluxs/filter.rb', line 54
def numeric? value
Float(value) != nil rescue false
end
|
#process(event, config) ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/mushy/fluxs/filter.rb', line 28
def process event, config
differences = [:equal, :notequal]
.select { |x| config[x].is_a? Hash }
.map { |x| config[x].map { |k, v| { m: x, k: k, v1: v } } }
.flatten
.map { |x| x[:v2] = event[x[:k]] ; x }
.map { |x| [x[:m], x[:v1], x[:v2]] }
.reject { |x| self.send x[0], x[1], x[2] }
differences.count == 0 ? event : nil
end
|