Sha256: 79b7043cc862fed62e4b477be067b1dd98fc3fd9e511ab82059a3744eb584f1a

Contents?: true

Size: 1.37 KB

Versions: 3

Compression:

Stored size: 1.37 KB

Contents

module Rlottery
  module RuleSet
    class BaseRuleSet

      def initialize(args)
        @original_slots = args[:slots].values
        @slots = @original_slots
        @slots_count = @slots.size
        @slots_position = 0
        order_slots


        @original_participants = args[:participants].values
        @participants = @original_participants
        @participants_count = @participants.size
        @participants_position = 0
        order_participants
      end

      def order_participants
        @participants = @participants.sort_by{rand}
      end

      def order_slots
        @slots = @slots.sort_by{rand}
      end

      def participants_turnover
      end

      def slots_turnover
      end

      def next_slot
        s = @slots[@slots_position]
        @slots_position += 1
        if @slots_count == @slots_position
          @slots_position = 0
        end
        s
      end

      def next_participant
        p = @participants[@participants_position]
        @participants_position += 1
        if @participants_count == @participants_position
          @participants_position = 0
        end
        p
      end

      def run!
        @participants.each do |p|
          assign_pair(next_slot, p)
        end
      end

      def assign_pair(one, the_other)
        one.assignments << the_other
        the_other.assignments << one
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
jlindley-rlottery-0.1.2 lib/rlottery/rule_set.rb
jlindley-rlottery-0.1.3 lib/rlottery/rule_set.rb
jlindley-rlottery-0.1.4 lib/rlottery/rule_set.rb