Class: Decidim::Elections::Answer

Inherits:
ApplicationRecord show all
Includes:
HasAttachmentCollections, HasAttachments, Loggable, Resourceable, Traceable
Defined in:
decidim-elections/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

Methods included from HasAttachments

#attachment_context

Instance Method Details

#proposalsObject

Public: Get all the proposals related to the answer

Returns an ActiveRecord::Relation.



26
27
28
# File 'decidim-elections/app/models/decidim/elections/answer.rb', line 26

def proposals
  linked_resources(:proposals, "related_proposals")
end

#results_percentageObject

A result percentage relative to the question Returns a Float.



41
42
43
# File 'decidim-elections/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_totalObject

Sum all valid results from different origins (PollingStations or BulletinBoard)



35
36
37
# File 'decidim-elections/app/models/decidim/elections/answer.rb', line 35

def results_total
  @results_total ||= results.valid_answers.sum(:value)
end

#slugObject



30
31
32
# File 'decidim-elections/app/models/decidim/elections/answer.rb', line 30

def slug
  "answer-#{id}"
end