Skip to content

Instantly share code, notes, and snippets.

@joemsak

joemsak/iteraptor.rb

Created Apr 23, 2020
Embed
What would you like to do?
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