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
44
45
46
47
48
# File 'decidim-elections/app/models/decidim/elections/answer.rb', line 41

def results_percentage
  @results_percentage ||= begin
    return 0 unless results_total.positive?

    result = results_total.to_f / question.results_total * 100.0
    result.round
  end
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