Class: Xipai::Arrangement::Lottery

Inherits:
Base
  • Object
show all
Defined in:
lib/xipai/arrangement/lottery.rb

Instance Attribute Summary

Attributes inherited from Base

#params

Instance Method Summary collapse

Methods inherited from Base

#__attributes__, #__require_attributes__, attributes, #dump_replay_yaml, #initialize, #method_missing, #method_missing_hook, require_attributes, #to_replay_data, #valid!

Constructor Details

This class inherits a constructor from Xipai::Arrangement::Base

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Xipai::Arrangement::Base

Instance Method Details

#applyObject



16
17
18
19
20
21
22
23
# File 'lib/xipai/arrangement/lottery.rb', line 16

def apply
  _hashcode, _shuffled = Xipai::Core.scrumble!(
    key_words, hashcode, items, params
  ).tap {|me| break *[me[:hashcode], me[:shuffled]]}
  _result_set = lottery(_shuffled, number_of_winners)

  return Xipai::Result.new(mode, _hashcode, _result_set, params)
end

#lottery(_items, _number_of_winners) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'lib/xipai/arrangement/lottery.rb', line 25

def lottery(_items, _number_of_winners)
  return Some[_number_of_winners].match do |m|
    m.some(->(x){x > 0}) {|x|
      _items.sample(x, random: Random.new(
        JSON.generate(_items).bytes.reduce(:*)
      ))
    }
    m.some() {raise "Error: number_of_winners"}
  end
end