Files
nairobi/app/lib/poll_option_finder.rb
Javi Martín 7f749bb9bb Add and apply Style/CollectionQuerying rubocop rule
This rule was added in rubocop 1.77. We were following it most of the
time. It makes the code more readable in my humble opinion.
2025-11-05 14:27:12 +01:00

32 lines
657 B
Ruby

class PollOptionFinder
attr_reader :question
def initialize(question)
@question = question
end
def manageable_choices
choices_map.select { |choice, ids| ids.one? }
end
def unmanageable_choices
choices_map.reject { |choice, ids| ids.one? }
end
private
def choices_map
@choices_map ||= existing_choices.to_h do |choice|
[choice, options.where("lower(title) = lower(?)", choice).distinct.ids]
end
end
def options
question.question_options.joins(:translations).reorder(:id)
end
def existing_choices
question.answers.where(option_id: nil).distinct.pluck(:answer)
end
end