Class: Decidim::Sortitions::Admin::Draw

Inherits:
Object
  • Object
show all
Defined in:
decidim-sortitions/app/services/decidim/sortitions/admin/draw.rb

Overview

This class represents a draw for selecting proposals.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sortition) ⇒ Draw

Initializes the draw class. Receives a sortition.



16
17
18
# File 'decidim-sortitions/app/services/decidim/sortitions/admin/draw.rb', line 16

def initialize(sortition)
  @sortition = sortition
end

Instance Attribute Details

#sortitionObject (readonly)

Returns the value of attribute sortition.



8
9
10
# File 'decidim-sortitions/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 'decidim-sortitions/app/services/decidim/sortitions/admin/draw.rb', line 11

def self.for(sortition)
  new(sortition).results
end

Instance Method Details

#proposalsObject



25
26
27
# File 'decidim-sortitions/app/services/decidim/sortitions/admin/draw.rb', line 25

def proposals
  @proposals ||= ParticipatorySpaceProposals.for(sortition).to_a
end

#resultsObject

Executes the draw and return the selected proposal ids.



21
22
23
# File 'decidim-sortitions/app/services/decidim/sortitions/admin/draw.rb', line 21

def results
  proposals.sample(sortition.target_items, random: Random.new(sortition.seed)).pluck(:id)
end