class Rigor::Test

Public Class Methods

find_by_name(name) click to toggle source
# File lib/rigor/test.rb, line 3
def self.find_by_name(name)
  Test.new
end

Public Instance Methods

random_treatment() click to toggle source
# File lib/rigor/test.rb, line 11
def random_treatment
  treatment_max = 0
  assignment = rand(cumulative_weights)
  treatments.each do |treatment|
    treatment_max += treatment.weight
    return treatment if assignment < treatment_max
  end
end
treatments() click to toggle source
# File lib/rigor/test.rb, line 7
def treatments
  [Treatment.new(:control), Treatment.new(:test)]
end

Protected Instance Methods

cumulative_weights() click to toggle source
# File lib/rigor/test.rb, line 22
def cumulative_weights
  treatments.map(&:weight).sum
end