Sha256: 2149a4796854e56fb30ed11ed37fb89f95b895b0ebf32a48917b0fa051c6c2ab

Contents?: true

Size: 859 Bytes

Versions: 9

Compression:

Stored size: 859 Bytes

Contents

# {
#   "convert": {
#     "field": "duration",
#     "type": "integer"
#   }
# }
module Anschel
  class Filter
    def convert conf, log
      log.debug event: 'compile-filter', filter: 'convert', conf: conf
      field = conf.delete :field
      type  = conf.delete :type

      raise 'Missing required "field" for "convert" filter' if field.nil?
      raise 'Missing required "type" for "convert" filter' if type.nil?

      field = field.to_sym

      type_conversions = {
        'integer' => :to_i,
        'float'   => :to_f,
        'string'  => :to_s
      }

      log.debug event: 'compiled-filter', filter: 'convert', \
        field: field, type: type

      lambda do |event|
        return event unless event.has_key? field
        event[field] = event[field].send type_conversions[type]
        filtered event, conf
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
anschel-0.6.1 lib/anschel/filter/convert.rb
anschel-0.6.0 lib/anschel/filter/convert.rb
anschel-0.5.0 lib/anschel/filter/convert.rb
anschel-0.4.1 lib/anschel/filter/convert.rb
anschel-0.4.0 lib/anschel/filter/convert.rb
anschel-0.3.2 lib/anschel/filter/convert.rb
anschel-0.3.1 lib/anschel/filter/convert.rb
anschel-0.3.0 lib/anschel/filter/convert.rb
anschel-0.2.0 lib/anschel/filter/convert.rb