Sha256: 6097ca38381267eee1b068542ac245f54028cc6d84aa38eb44165c22d946847b

Contents?: true

Size: 980 Bytes

Versions: 12

Compression:

Stored size: 980 Bytes

Contents

# {
#   "convert": {
#     "field": "duration",
#     "type": "integer"
#   }
# }
module Anschel
  class Filter
    def convert conf, stats, log
      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
      }

      stats.create 'filter-convert'
      stats.create 'filter-convert-skipped'

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



      lambda do |event|
        unless event.has_key? field
          stats.inc 'filter-convert-skipped'
          return event
        end

        event[field] = event[field].send type_conversions[type]
        stats.inc 'filter-convert'
        filtered event, conf
      end

    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
anschel-0.7.12 lib/anschel/filter/convert.rb
anschel-0.7.11 lib/anschel/filter/convert.rb
anschel-0.7.10 lib/anschel/filter/convert.rb
anschel-0.7.9 lib/anschel/filter/convert.rb
anschel-0.7.8 lib/anschel/filter/convert.rb
anschel-0.7.7 lib/anschel/filter/convert.rb
anschel-0.7.6 lib/anschel/filter/convert.rb
anschel-0.7.5 lib/anschel/filter/convert.rb
anschel-0.7.4 lib/anschel/filter/convert.rb
anschel-0.7.3 lib/anschel/filter/convert.rb
anschel-0.7.2 lib/anschel/filter/convert.rb
anschel-0.7.1 lib/anschel/filter/convert.rb