class Mushy::Filter

Public Class Methods

details() click to toggle source
# 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

Public Instance Methods

equal(a, b) click to toggle source
# 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) click to toggle source
# File lib/mushy/fluxs/filter.rb, line 50
def notequal a, b
  equal(a, b) == false
end
numeric?(value) click to toggle source
# File lib/mushy/fluxs/filter.rb, line 54
def numeric? value
  Float(value) != nil rescue false
end
process(event, config) click to toggle source
# 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