class ABSplit::Test

This class is responsible for spliting the population using the experiment name passed as a parameter. It will always return an experiment name or a NoValidExperiment error in case is chosen any unknown experiment.

Attributes

experiment[RW]

Public Class Methods

split(name, value) click to toggle source
# File lib/a_b_split/test.rb, line 11
def split(name, value)
  self.experiment = find(name)

  raise ABSplit::NoValidExperiment unless experiment

  function.value_for(value, *options)
end

Private Class Methods

find(experiment) click to toggle source
# File lib/a_b_split/test.rb, line 23
def find(experiment)
  ABSplit.configuration.experiments[experiment]
end
function() click to toggle source
# File lib/a_b_split/test.rb, line 27
def function
  function = 'WeightedSplit'

  unless experiment.is_a?(Array)
    function = experiment['algorithm'] if experiment['algorithm']

    begin
      ABSplit::Functions.const_get(function)
    rescue NameError
      raise ABSplit::NoValidExperiment
    end
  end

  ABSplit::Functions.const_get(function)
end
options() click to toggle source
# File lib/a_b_split/test.rb, line 43
def options
  experiment.is_a?(Array) ? experiment : experiment['options']
end