Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Choice < Struct.new( :label, :votes, :percentage )
- def results
- # choices = [ 'Alumni', 'College', 'High School', nil, nil, nil ]
- CHOICES = [ 'A', 'B', 'C', 'D', 'E', 'other' ]
- def choices_hash
- {
- 'A' => choice_a,
- 'B' => choice_b
- }
- end
- choices_hash.each do |key, choice|
- if choice.present?
- # option 1
- yield Choice.new( choice, get_total_votes_for(key), get_percentage_for(key) )
- # option 2
- yield({
- 'label' => choice,
- 'votes' => get_total_votes_for(CHOICES[index]),
- 'percentage' => get_percentage_for(CHOICES[index])
- })
- end
- end
- end
Add Comment
Please, Sign In to add comment