Class: ABTester::ChoiceOptions
- Inherits:
-
Object
- Object
- ABTester::ChoiceOptions
- Defined in:
- lib/ab_tester/choice_options.rb
Instance Method Summary collapse
-
#initialize(options_hash) ⇒ ChoiceOptions
constructor
A new instance of ChoiceOptions.
- #shuffle ⇒ Object
Constructor Details
#initialize(options_hash) ⇒ ChoiceOptions
Returns a new instance of ChoiceOptions.
2 3 4 5 6 7 8 9 10 |
# File 'lib/ab_tester/choice_options.rb', line 2 def initialize() @total_rank = 0 @ranked_keys = [] .each do |key, value| @total_rank += value @ranked_keys << [key, @total_rank] end end |
Instance Method Details
#shuffle ⇒ Object
12 13 14 15 |
# File 'lib/ab_tester/choice_options.rb', line 12 def shuffle random_value = rand @total_rank @ranked_keys.find{ |key, rank| random_value < rank }[0] end |