Skip to content

Instantly share code, notes, and snippets.

@andrewvc
Last active March 27, 2017 23:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewvc/e84c477ce63a9a65ed4c79bab487aceb to your computer and use it in GitHub Desktop.
Save andrewvc/e84c477ce63a9a65ed4c79bab487aceb to your computer and use it in GitHub Desktop.
define_filter :keymapper do
process do |event|
keys = event.get('[keys]')
vals = event.get('[vals]')
next unless keys && vals && !keys.empty? && !vals.empty?
keys.each.with_index do |key,i|
event.set(key, vals[i])
end
event
end
test(
"keys map to vals",
:input => { "keys" => ["a", "b"], "vals" => [1,2] },
:output => { "keys" => ["a", "b"], "vals" => 1,2, "a" => 1, "b" => 2 }
)
test(
"no keys, not problem",
:input => { "a" => "b" },
:output => {}
)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment