Class: Decidim::Sortitions::Admin::Draw
- Inherits:
-
Object
- Object
- Decidim::Sortitions::Admin::Draw
- Defined in:
- app/services/decidim/sortitions/admin/draw.rb
Overview
This class represents a draw for selecting proposals.
Instance Attribute Summary collapse
-
#sortition ⇒ Object
readonly
Returns the value of attribute sortition.
Class Method Summary collapse
-
.for(sortition) ⇒ Object
Sugar syntax.
Instance Method Summary collapse
-
#initialize(sortition) ⇒ Draw
constructor
Initializes the draw class.
- #proposals ⇒ Object
-
#results ⇒ Object
Executes the draw and return the selected proposal ids.
Constructor Details
#initialize(sortition) ⇒ Draw
Initializes the draw class. Receives a sortition.
16 17 18 |
# File 'app/services/decidim/sortitions/admin/draw.rb', line 16 def initialize(sortition) @sortition = sortition end |
Instance Attribute Details
#sortition ⇒ Object (readonly)
Returns the value of attribute sortition.
8 9 10 |
# File 'app/services/decidim/sortitions/admin/draw.rb', line 8 def sortition @sortition end |
Class Method Details
.for(sortition) ⇒ Object
Sugar syntax. Retrieves the list of selected proposals.
11 12 13 |
# File 'app/services/decidim/sortitions/admin/draw.rb', line 11 def self.for(sortition) new(sortition).results end |
Instance Method Details
#proposals ⇒ Object
25 26 27 |
# File 'app/services/decidim/sortitions/admin/draw.rb', line 25 def proposals @proposals ||= ParticipatorySpaceProposals.for(sortition).to_a end |
#results ⇒ Object
Executes the draw and return the selected proposal ids.
21 22 23 |
# File 'app/services/decidim/sortitions/admin/draw.rb', line 21 def results proposals.sample(sortition.target_items, random: Random.new(sortition.seed)).pluck(:id) end |