Class: Decidim::Elections::Answer
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Decidim::Elections::Answer
- Includes:
- HasAttachmentCollections, HasAttachments, Resourceable, Loggable, Traceable
- Defined in:
- app/models/decidim/elections/answer.rb
Overview
The data store for an Answer in the Decidim::Elections component. It stores a title, description and related resources and attachments.
Instance Method Summary collapse
-
#proposals ⇒ Object
Public: Get all the proposals related to the answer.
-
#results_percentage ⇒ Object
A result percentage relative to the question Returns a Float.
-
#results_total ⇒ Object
Sum all valid results from different origins (PollingStations or BulletinBoard).
- #slug ⇒ Object
Instance Method Details
#proposals ⇒ Object
Public: Get all the proposals related to the answer
Returns an ActiveRecord::Relation.
26 27 28 |
# File 'app/models/decidim/elections/answer.rb', line 26 def proposals linked_resources(:proposals, "related_proposals") end |
#results_percentage ⇒ Object
A result percentage relative to the question Returns a Float.
41 42 43 |
# File 'app/models/decidim/elections/answer.rb', line 41 def results_percentage @results_percentage ||= results_total.positive? ? (results_total.to_f / question.results_total * 100.0).round : 0 end |
#results_total ⇒ Object
Sum all valid results from different origins (PollingStations or BulletinBoard)
35 36 37 |
# File 'app/models/decidim/elections/answer.rb', line 35 def results_total @results_total ||= results.valid_answers.sum(:value) end |
#slug ⇒ Object
30 31 32 |
# File 'app/models/decidim/elections/answer.rb', line 30 def slug "answer-#{id}" end |