Class: Decidim::Elections::Question
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Decidim::Elections::Question
- Includes:
- Resourceable, Loggable, Traceable
- Defined in:
- app/models/decidim/elections/question.rb
Overview
The data store for a Question in the Decidim::Elections component. It stores a title and a maximum number of selection that voters can choose.
Instance Method Summary collapse
- #blank_votes ⇒ Object
-
#blank_votes_percentage ⇒ Object
A result percentage relative to the question Returns a Float.
-
#nota_option? ⇒ Boolean
Public: Checks if the question accepts a blank/NOTA as an answer.
- #results_total ⇒ Object
- #slug ⇒ Object
-
#valid_max_selection? ⇒ Boolean
Public: Checks if enough answers are given for max_selections attribute.
Instance Method Details
#blank_votes ⇒ Object
33 34 35 |
# File 'app/models/decidim/elections/question.rb', line 33 def blank_votes @blank_votes ||= results.blank_answers.sum(:value) end |
#blank_votes_percentage ⇒ Object
A result percentage relative to the question Returns a Float.
43 44 45 |
# File 'app/models/decidim/elections/question.rb', line 43 def blank_votes_percentage @blank_votes_percentage ||= results_total.positive? ? (blank_votes.to_f / results_total * 100.0).round : 0 end |
#nota_option? ⇒ Boolean
Public: Checks if the question accepts a blank/NOTA as an answer
Returns a boolean.
29 30 31 |
# File 'app/models/decidim/elections/question.rb', line 29 def nota_option? @nota_option ||= min_selections.zero? end |
#results_total ⇒ Object
37 38 39 |
# File 'app/models/decidim/elections/question.rb', line 37 def results_total @results_total ||= answers.sum(&:results_total) + blank_votes end |
#slug ⇒ Object
47 48 49 |
# File 'app/models/decidim/elections/question.rb', line 47 def slug "question-#{id}" end |
#valid_max_selection? ⇒ Boolean
Public: Checks if enough answers are given for max_selections attribute
Returns a boolean.
22 23 24 |
# File 'app/models/decidim/elections/question.rb', line 22 def valid_max_selection? max_selections <= answers.count end |