Class: Modesty::Experiment::Builder
- Inherits:
-
Object
- Object
- Modesty::Experiment::Builder
show all
- Defined in:
- lib/modesty/experiment/stats.rb,
lib/modesty/experiment/builder.rb
Instance Method Summary
collapse
Constructor Details
#initialize(exp) ⇒ Builder
Returns a new instance of Builder.
13
14
15
|
# File 'lib/modesty/experiment/builder.rb', line 13
def initialize(exp)
@exp = exp
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
4
5
6
7
8
9
10
11
|
# File 'lib/modesty/experiment/builder.rb', line 4
def method_missing(name, *args)
if Experiment::ATTRIBUTES.include?(name) && args.count > 0
val = (args.count == 1) ? args[0] : args
@exp.instance_variable_set("@#{name}", val)
else
@exp.send(name)
end
end
|
Instance Method Details
#alternatives(*alts) ⇒ Object
17
18
19
20
|
# File 'lib/modesty/experiment/builder.rb', line 17
def alternatives(*alts)
alts.unshift :control unless alts.include? :control
@exp.instance_variable_set("@alternatives", alts)
end
|
#conversion(name, options = {}, &blk) ⇒ Object
43
44
45
|
# File 'lib/modesty/experiment/stats.rb', line 43
def conversion(name, options={}, &blk)
@exp.stats[name] = ConversionStat.new(@exp, name, options, &blk)
end
|
#distribution(name, options = {}, &blk) ⇒ Object
39
40
41
|
# File 'lib/modesty/experiment/stats.rb', line 39
def distribution(name, options={}, &blk)
@exp.stats[name] = DistributionStat.new(@exp, name, options, &blk)
end
|
#metric(sym, options = {}) ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/modesty/experiment/builder.rb', line 32
def metric(sym, options={})
@exp.metrics << (Modesty.metrics[sym] || raise(
Modesty::NoMetricError,
"Undefined metric #{sym.inspect} in experiment #{@exp}"
))
if as = options.delete(:as)
@exp.metric_contexts[sym] = as.to_sym
end
raise <<-msg.squish unless options.empty?
unrecognized options
#{options.keys.inspect}
msg
end
|
#metrics(*args) ⇒ Object
22
23
24
25
26
27
28
29
30
|
# File 'lib/modesty/experiment/builder.rb', line 22
def metrics(*args)
metrics = args.map do |s|
Modesty.metrics[s] || raise(
Modesty::NoMetricError,
"Undefined metric '#{s.inspect}' in experiment #{@exp}'"
)
end
@exp.instance_variable_set("@metrics", metrics)
end
|