Class: SplitCat::Config

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/split_cat/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



11
12
13
14
15
# File 'lib/split_cat/config.rb', line 11

def initialize
  @cookie_expiration = 10.years
  @experiments = HashWithIndifferentAccess.new
  @name = nil
end

Instance Attribute Details

Returns the value of attribute cookie_expiration.



9
10
11
# File 'lib/split_cat/config.rb', line 9

def cookie_expiration
  @cookie_expiration
end

#experimentsObject (readonly)

Returns the value of attribute experiments.



8
9
10
# File 'lib/split_cat/config.rb', line 8

def experiments
  @experiments
end

Instance Method Details

#experiment(name, description = nil) {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/split_cat/config.rb', line 17

def experiment( name, description = nil )
  @name =  name.to_sym
  @experiments[ @name ] = {
      :experiment => {
          :name => name,
          :description => description
      },
      :goals => [],
      :hypotheses => []
  }

  yield self
end

#goal(name, description = nil) ⇒ Object



35
36
37
# File 'lib/split_cat/config.rb', line 35

def goal( name, description = nil )
  @experiments[ @name ][ :goals ] << { :name => name, :description => description }
end

#hypothesis(name, weight, description = nil) ⇒ Object



31
32
33
# File 'lib/split_cat/config.rb', line 31

def hypothesis( name, weight, description = nil )
  @experiments[ @name ][ :hypotheses ] << { :name => name, :weight => weight, :description => description }
end

#template(name) ⇒ Object



39
40
41
42
43
44
45
46
47
# File 'lib/split_cat/config.rb', line 39

def template( name )
  return nil unless data = @experiments[ name ]

  experiment = Experiment.new( data[ :experiment ] )
  data[ :hypotheses ].each { |h| experiment.hypotheses << Hypothesis.new( h ) }
  data[ :goals ].each { |g| experiment.goals << Goal.new( g ) }

  return experiment
end