Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. class Appearance < ApplicationRecord
  2. belongs_to :queen
  3. belongs_to :episode
  4.  
  5. def get_appearances
  6. #### iterate through each season, pulling episode ids and setting the index of each iterative episodes' ranks
  7. Season.all.each do |season|
  8. season.episodes.each.with_index do |episode, index|
  9. episode_id = episode.id
  10. rank_index = index + 2
  11.  
  12. #### clean the contestants array for Appearance creation
  13. contestants = episode.contestants.split(", ").map do |contestant|
  14. contestant.gsub(/[^0-9a-z%&!\n\/(). ]/i, '').strip
  15. end
  16. contestants = contestants.in_groups_of(season.episodes.length + 1)
  17.  
  18. #### iterate through the array of contestants to create an Appearance for each Episode
  19. contestants.map do |contestant|
  20. Appearance.create(
  21. episode_id: episode_id,
  22.  
  23. #### use the contestants list as it appeared on the season's Fandom page to find the corresponding Queens
  24. queen_id: Queen.find_or_create_by(drag_name: contestant[0]).id,
  25.  
  26. #### set the queen's numerical rank for her appearance in each episode
  27. rank: contestant[rank_index]
  28. )
  29. end
  30. end
  31. end
  32. end
  33. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement