Class: Dap::Filter::FilterAnnotate

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/dap/filter/simple.rb

Overview

Applies some simple annotation to the given fields, adding another field name with the appended annotation type, i.e.:

$ echo ‘“foo”:“blah”’ | dap json stdin + annotate foo=length + json “foo”:“bar”,“foo.length”:4

Instance Attribute Summary

Attributes included from Base

#name, #opts

Instance Method Summary collapse

Methods included from Base

#initialize

Instance Method Details

#process(doc) ⇒ Object



255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# File 'lib/dap/filter/simple.rb', line 255

def process(doc)
  self.opts.each_pair do |k,v|
    if doc.has_key?(k)
      case v
      when 'length'
        doc["#{k}.length"] = doc[k].length
      when 'size'
        doc["#{k}.size"] = doc[k].size
      else
        fail "Unsupported annotation '#{v}'"
      end
    end
  end
  [ doc ]
end