Skip to content

Instantly share code, notes, and snippets.

@joemsak
Created April 23, 2020 18:00
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 joemsak/100ddeefcfa7affcc2661b1ee146771f to your computer and use it in GitHub Desktop.
Save joemsak/100ddeefcfa7affcc2661b1ee146771f to your computer and use it in GitHub Desktop.
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