Class: Dap::Filter::FilterRenameSubkeyMatch
- Inherits:
-
Object
- Object
- Dap::Filter::FilterRenameSubkeyMatch
- Includes:
- Base
- Defined in:
- lib/dap/filter/simple.rb
Overview
Example below replaces periods with underscores in the names of all keys one level below ‘my_key’ rename_subkey_match my_key ‘.’ ‘_’
Instance Attribute Summary
Attributes included from Base
Instance Method Summary collapse
-
#initialize(args) ⇒ FilterRenameSubkeyMatch
constructor
A new instance of FilterRenameSubkeyMatch.
- #process(doc) ⇒ Object
Constructor Details
#initialize(args) ⇒ FilterRenameSubkeyMatch
Returns a new instance of FilterRenameSubkeyMatch.
85 86 87 88 89 |
# File 'lib/dap/filter/simple.rb', line 85 def initialize(args) super fail "Expected 3 arguments to '#{self.name}' but got #{args.size}" unless args.size == 3 self.opts = args end |
Instance Method Details
#process(doc) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/dap/filter/simple.rb', line 91 def process(doc) temp_field = {} field, original, updated = self.opts return [ doc ] unless doc[field].is_a?(::Hash) doc[field].each_key do |k| new_k = k.gsub(original, updated) temp_field[new_k] = doc[field][k] end doc[field] = temp_field [ doc ] end |