Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
1,057
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. mapping = {
  2. "American" => ["American Fusion","American Sea food","Beef Burger","Burgers","Burger","Gourmet Burger","Gourmet Sliders","Fried Chicken","Southern","Steak","Tex Mex"],
  3. "Arabic" => ["Arabian","Arabic Grills","Arabic Sweets","Bahraini","Bahraini Food","Egyptian Food","Egyptian","Lebanese","Emirati","Falafel","Kuwaiti","Koshary","Manakeesh","Manakish","Iraqi","Jordanian","Palestinian","Qatari","Shami","Syrian","Yemeni","Bedouin"],
  4. "Asian" => ["Chinese","Indian","Thai","Vietnamese","Indian Food","Indian Taste","Japanese","Japanese Taste","Oriental","Pakistani","Korean","Modern Indian","Modern Asian","Philippines","Phillipino","Sushi"],
  5. "Bakery" => ["Bread","Pastries","Pastry"],
  6. "Beverages" => ["Cocktails","Cold Drinks","Drinks","Milkshakes","Juices","Karak"],
  7. "Coffee" => ["Latte","Coffee Roasters","Specialty Coffee"],
  8. "Desserts" => ["Cupcakes","Cupcakes","Crepes","Crepe","Cookies","Candy","Cake","Cakes","Lugimat","Kunafah","Baklava","Pie","Sweets","Waffle","Chocolate","Ice Cream","Frozen Yogurt","Yogurt"],
  9. "European" => ["Armenian","Azerbaijan","Belarusian","Bulgarian","Georgian","Kazakh","Moldovan","Romanian","Russian","Ukrainian","British","Danish","Estonian","Faroese","Finnish","Icelandic","Irish","Latvian","Lithuanian","Norwegian","Swedish","Belgian","Dutch"],
  10. "Latin American" => ["Argentina","Brazilian","Mexican","Peruvian"],
  11. "Mediterranean" => ["French","Greek","Spanish","Algeria","Libya","Tunisia","Morocco","Portuguese"],
  12. "Middle Eastern" => ["Moroccan","Persian","Iranian","Afghani","Armenian"],
  13. "Italian" => ["Neapolitan", "Pasta"],
  14. "Healthy" => ["Healthy Food","Diet Restaurant"],
  15. "Vegan" => "Vegan Cafe",
  16. "Turkish" => "Doner",
  17. "Seafood" => "Fish"
  18. }
  19. Country.set_country_attr 1
  20. mapping.map do |k, v|
  21. old_ids = Cousin.where(name: v).pluck(:id)
  22. p old_ids
  23. if old_ids.present?
  24. new_cousin = Cousin.where(name: k, country_id: Country.country_id_cache).first_or_create
  25. CousinsLocation.unscoped.where(cousin_id: old_ids).update_all(cousin_id: new_cousin.id)
  26. Cousin.where(id: old_ids).update_all(active: false)
  27. new_cousin.update_attributes(active: true)
  28. end
  29. end
  30. to_be_added = ["Fast Food","Pizza","Salads","Sandwiches","Shawerma & Doner","African"]
  31. removed_cousins = Cousin.filter_by_vertical(1).where(active: true).pluck(:name) - (mapping.keys + to_be_added)
  32. Cousin.where(name: removed_cousins).update_all(active: false)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement