Class: Decidim::Elections::Election
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Decidim::Elections::Election
- Includes:
- Forms::HasQuestionnaire, HasAttachmentCollections, HasAttachments, HasComponent, Publicable, Resourceable, TranslatableResource, Loggable, Traceable
- Defined in:
- app/models/decidim/elections/election.rb
Overview
The data store for an Election in the Decidim::Elections component. It stores a title, description and any other useful information to perform an election.
Class Method Summary collapse
Instance Method Summary collapse
-
#allow_resource_permissions? ⇒ Boolean
Public: Overrides the Resourceable concern method to allow setting permissions at resource level.
-
#blocked? ⇒ Boolean
Public: Checks if the election has a blocked_at value.
-
#finished? ⇒ Boolean
Public: Checks if the election finished.
-
#maximum_hours_before_start? ⇒ Boolean
Public: Checks if the election start_time is maximum some hours before than the present time.
-
#minimum_answers? ⇒ Boolean
Public: Checks if the number of answers are minimum 2 for each question.
-
#minimum_hours_before_start? ⇒ Boolean
Public: Checks if the election start_time is minimum some hours later than the present time.
-
#ongoing? ⇒ Boolean
Public: Checks if the election ongoing now.
-
#results? ⇒ Boolean
Public: Checks if the election results are present.
-
#results_published? ⇒ Boolean
Public: Checks if the election results are published and election finished.
-
#started? ⇒ Boolean
Public: Checks if the election started.
- #trustee_action_required? ⇒ Boolean
-
#valid_questions? ⇒ Boolean
Public: Checks if the election questions are valid.
-
#voting_period_status ⇒ Object
Public: Gets the voting period status of the election.
Class Method Details
.log_presenter_class_for(_log) ⇒ Object
46 47 48 |
# File 'app/models/decidim/elections/election.rb', line 46 def self.log_presenter_class_for(_log) Decidim::Elections::AdminLog::ElectionPresenter end |
Instance Method Details
#allow_resource_permissions? ⇒ Boolean
Public: Overrides the Resourceable concern method to allow setting permissions at resource level
138 139 140 |
# File 'app/models/decidim/elections/election.rb', line 138 def true end |
#blocked? ⇒ Boolean
Public: Checks if the election has a blocked_at value
Returns a boolean.
133 134 135 |
# File 'app/models/decidim/elections/election.rb', line 133 def blocked? blocked_at.present? end |
#finished? ⇒ Boolean
Public: Checks if the election finished
Returns a boolean.
60 61 62 |
# File 'app/models/decidim/elections/election.rb', line 60 def finished? end_time < Time.current end |
#maximum_hours_before_start? ⇒ Boolean
Public: Checks if the election start_time is maximum some hours before than the present time
Returns a boolean.
81 82 83 |
# File 'app/models/decidim/elections/election.rb', line 81 def maximum_hours_before_start? start_time < (Time.zone.at(Decidim::Elections.start_vote_maximum_hours_before_start.hours.from_now)) end |
#minimum_answers? ⇒ Boolean
Public: Checks if the number of answers are minimum 2 for each question
Returns a boolean.
88 89 90 |
# File 'app/models/decidim/elections/election.rb', line 88 def minimum_answers? questions.all? { |question| question.answers.size > 1 } end |
#minimum_hours_before_start? ⇒ Boolean
Public: Checks if the election start_time is minimum some hours later than the present time
Returns a boolean.
74 75 76 |
# File 'app/models/decidim/elections/election.rb', line 74 def minimum_hours_before_start? start_time > (Time.zone.at(Decidim::Elections.setup_minimum_hours_before_start.hours.from_now)) end |
#ongoing? ⇒ Boolean
Public: Checks if the election ongoing now
Returns a boolean.
67 68 69 |
# File 'app/models/decidim/elections/election.rb', line 67 def ongoing? started? && !finished? end |
#results? ⇒ Boolean
Public: Checks if the election results are present
Returns a boolean.
102 103 104 |
# File 'app/models/decidim/elections/election.rb', line 102 def results? bb_tally_ended? || results_published? end |
#results_published? ⇒ Boolean
Public: Checks if the election results are published and election finished
Returns a boolean.
95 96 97 |
# File 'app/models/decidim/elections/election.rb', line 95 def results_published? bb_results_published? end |
#started? ⇒ Boolean
Public: Checks if the election started
Returns a boolean.
53 54 55 |
# File 'app/models/decidim/elections/election.rb', line 53 def started? start_time <= Time.current end |
#trustee_action_required? ⇒ Boolean
126 127 128 |
# File 'app/models/decidim/elections/election.rb', line 126 def trustee_action_required? bb_key_ceremony? || bb_tally? end |
#valid_questions? ⇒ Boolean
Public: Checks if the election questions are valid
Returns a boolean.
109 110 111 |
# File 'app/models/decidim/elections/election.rb', line 109 def valid_questions? questions.all?(&:valid_max_selection?) end |
#voting_period_status ⇒ Object
Public: Gets the voting period status of the election
Returns one of these symbols: upcoming, ongoing or finished
116 117 118 119 120 121 122 123 124 |
# File 'app/models/decidim/elections/election.rb', line 116 def voting_period_status if finished? :finished elsif started? :ongoing else :upcoming end end |