Guest User

Untitled

a guest
Jun 18th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. class Choice < Struct.new( :label, :votes, :percentage )
  2.  
  3. def results
  4. # choices = [ 'Alumni', 'College', 'High School', nil, nil, nil ]
  5. CHOICES = [ 'A', 'B', 'C', 'D', 'E', 'other' ]
  6.  
  7. def choices_hash
  8. {
  9. 'A' => choice_a,
  10. 'B' => choice_b
  11. }
  12. end
  13. choices_hash.each do |key, choice|
  14. if choice.present?
  15. # option 1
  16. yield Choice.new( choice, get_total_votes_for(key), get_percentage_for(key) )
  17.  
  18. # option 2
  19. yield({
  20. 'label' => choice,
  21. 'votes' => get_total_votes_for(CHOICES[index]),
  22. 'percentage' => get_percentage_for(CHOICES[index])
  23. })
  24. end
  25. end
  26. end
Add Comment
Please, Sign In to add comment