Sha256: 5fb4aaa40c522b4174b2cd7a825643c53d43203522ad962b19739cabd88eff2e

Contents?: true

Size: 810 Bytes

Versions: 89

Compression:

Stored size: 810 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module Sortitions
    module Admin
      # This class represents a draw for selecting proposals.
      class Draw
        attr_reader :sortition

        # Sugar syntax. Retrieves the list of selected proposals.
        def self.for(sortition)
          new(sortition).results
        end

        # Initializes the draw class. Receives a sortition.
        def initialize(sortition)
          @sortition = sortition
        end

        # Executes the draw and return the selected proposal ids.
        def results
          proposals.sample(sortition.target_items, random: Random.new(sortition.seed)).pluck(:id)
        end

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

Version data entries

89 entries across 89 versions & 1 rubygems

Version Path
decidim-sortitions-0.29.1 app/services/decidim/sortitions/admin/draw.rb
decidim-sortitions-0.28.4 app/services/decidim/sortitions/admin/draw.rb
decidim-sortitions-0.27.9 app/services/decidim/sortitions/admin/draw.rb
decidim-sortitions-0.29.0 app/services/decidim/sortitions/admin/draw.rb
decidim-sortitions-0.28.3 app/services/decidim/sortitions/admin/draw.rb
decidim-sortitions-0.27.8 app/services/decidim/sortitions/admin/draw.rb
decidim-sortitions-0.29.0.rc4 app/services/decidim/sortitions/admin/draw.rb
decidim-sortitions-0.29.0.rc3 app/services/decidim/sortitions/admin/draw.rb
decidim-sortitions-0.29.0.rc2 app/services/decidim/sortitions/admin/draw.rb
decidim-sortitions-0.29.0.rc1 app/services/decidim/sortitions/admin/draw.rb
decidim-sortitions-0.28.2 app/services/decidim/sortitions/admin/draw.rb
decidim-sortitions-0.27.7 app/services/decidim/sortitions/admin/draw.rb
decidim-sortitions-0.28.1 app/services/decidim/sortitions/admin/draw.rb
decidim-sortitions-0.27.6 app/services/decidim/sortitions/admin/draw.rb
decidim-sortitions-0.26.10 app/services/decidim/sortitions/admin/draw.rb
decidim-sortitions-0.26.9 app/services/decidim/sortitions/admin/draw.rb
decidim-sortitions-0.28.0 app/services/decidim/sortitions/admin/draw.rb
decidim-sortitions-0.27.5 app/services/decidim/sortitions/admin/draw.rb
decidim-sortitions-0.28.0.rc5 app/services/decidim/sortitions/admin/draw.rb
decidim-sortitions-0.28.0.rc4 app/services/decidim/sortitions/admin/draw.rb