Skip to content

Instantly share code, notes, and snippets.

@rameshk
Created February 3, 2011 08:10
Show Gist options
  • Save rameshk/809192 to your computer and use it in GitHub Desktop.
Save rameshk/809192 to your computer and use it in GitHub Desktop.
if params[:_search] == "true" && params[:filters].present?
filters = Hash.new
j = JSON.parse(params[:filters])
i=0
until j.fetch("rules").size == i
k = j.fetch("rules").to_a[i].values_at("field", "op", "data", "groupOp")
if k[1] == "cn"
k[1] = "matches"
k[2] = k[2]+"%"
elsif k[1] == "ge"
k[1] = "gte"
elsif k[1] == "le"
k[1] = "lte"
end
if k[3] == "AND"
k[3] = "&"
elsif k[3] == "OR"
k[3] = "|"
end
filters[("#{k[0]}").to_sym.send(("#{k[1]}").to_sym)] = "#{k[2]}"
i += 1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment