Class: SplitCat::Config
- Inherits:
-
Object
- Object
- SplitCat::Config
- Includes:
- Singleton
- Defined in:
- lib/split_cat/config.rb
Instance Attribute Summary collapse
-
#cookie_expiration ⇒ Object
Returns the value of attribute cookie_expiration.
-
#experiments ⇒ Object
readonly
Returns the value of attribute experiments.
Instance Method Summary collapse
- #experiment(name, description = nil) {|_self| ... } ⇒ Object
- #goal(name, description = nil) ⇒ Object
- #hypothesis(name, weight, description = nil) ⇒ Object
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #template(name) ⇒ Object
Constructor Details
#initialize ⇒ Config
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
#cookie_expiration ⇒ Object
Returns the value of attribute cookie_expiration.
9 10 11 |
# File 'lib/split_cat/config.rb', line 9 def @cookie_expiration end |
#experiments ⇒ Object (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
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 |