Created
April 23, 2020 18:00
-
-
Save joemsak/100ddeefcfa7affcc2661b1ee146771f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
query = "course" | |
original = { | |
"en"=>{ | |
"courses"=>"Courses", | |
"layouts"=>{ | |
"navigation"=>{ | |
"desktop"=>{ | |
"browse_courses"=>"Browse Courses", | |
"this_one"=>false | |
} | |
} | |
}, | |
"unrelated"=>{ | |
"dont"=>{ | |
"include"=>"this, please" | |
} | |
} | |
} | |
} | |
modified = original.iteraptor.map { |_, (key, value)| | |
/#{query}/i.match?(String(value)) ? [key, value] : nil | |
} | |
modified #=> { | |
"en"=>{ | |
"courses"=>"Courses", | |
"layouts"=>{ | |
"navigation"=>{ | |
"desktop"=>{ | |
"browse_courses"=>"Browse Courses" | |
} | |
} | |
}, | |
"unrelated"=>{ | |
"dont"=>[] | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment