Class: Growthbook::InlineExperiment

Inherits:
Object
  • Object
show all
Defined in:
lib/growthbook/inline_experiment.rb

Overview

Class for creating an inline experiment for evaluating

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ InlineExperiment



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/growthbook/inline_experiment.rb', line 69

def initialize(options = {})
  @key = get_option(options, :key, '').to_s
  @variations = get_option(options, :variations, [])
  @weights = get_option(options, :weights)
  @active = get_option(options, :active, true)
  @coverage = get_option(options, :coverage, 1.0)
  @ranges = get_option(options, :ranges)
  @condition = get_option(options, :condition)
  @namespace = get_option(options, :namespace)
  @force = get_option(options, :force)
  @hash_attribute = get_option(options, :hash_attribute) || get_option(options, :hashAttribute) || 'id'
  @hash_version = get_option(options, :hash_version) || get_option(options, :hashVersion)
  @meta = get_option(options, :meta)
  @filters = get_option(options, :filters)
  @seed = get_option(options, :seed)
  @name = get_option(options, :name)
  @phase = get_option(options, :phase)
  @fallback_attribute = get_option(options, :fallback_attribute) || get_option(options, :fallbackAttribute)
  @disable_sticky_bucketing = get_option(options, :disable_sticky_bucketing, false) || get_option(options, :disableStickyBucketing, false)
  @bucket_version = get_option(options, :bucket_version) || get_option(options, :bucketVersion) || 0
  @min_bucket_version = get_option(options, :min_bucket_version) || get_option(options, :minBucketVersion) || 0
  @parent_conditions = get_option(options, :parent_conditions) || get_option(options, :parentConditions) || []

  return unless @disable_sticky_bucketing

  @fallback_attribute = nil
end

Instance Attribute Details

#activetrue, false



16
17
18
# File 'lib/growthbook/inline_experiment.rb', line 16

def active
  @active
end

#bucket_versioninteger



61
62
63
# File 'lib/growthbook/inline_experiment.rb', line 61

def bucket_version
  @bucket_version
end

#conditionHash



25
26
27
# File 'lib/growthbook/inline_experiment.rb', line 25

def condition
  @condition
end

#coverageFloat



19
20
21
# File 'lib/growthbook/inline_experiment.rb', line 19

def coverage
  @coverage
end

#disable_sticky_bucketingbool?



58
59
60
# File 'lib/growthbook/inline_experiment.rb', line 58

def disable_sticky_bucketing
  @disable_sticky_bucketing
end

#fallback_attributeString?



55
56
57
# File 'lib/growthbook/inline_experiment.rb', line 55

def fallback_attribute
  @fallback_attribute
end

#filtersArray<Hash>



43
44
45
# File 'lib/growthbook/inline_experiment.rb', line 43

def filters
  @filters
end

#forceinteger?



31
32
33
# File 'lib/growthbook/inline_experiment.rb', line 31

def force
  @force
end

#hash_attributeString



34
35
36
# File 'lib/growthbook/inline_experiment.rb', line 34

def hash_attribute
  @hash_attribute
end

#hash_versionInteger



37
38
39
# File 'lib/growthbook/inline_experiment.rb', line 37

def hash_version
  @hash_version
end

#keyString



7
8
9
# File 'lib/growthbook/inline_experiment.rb', line 7

def key
  @key
end

#metaArray<Hash>



40
41
42
# File 'lib/growthbook/inline_experiment.rb', line 40

def meta
  @meta
end

#min_bucket_versioninteger



64
65
66
# File 'lib/growthbook/inline_experiment.rb', line 64

def min_bucket_version
  @min_bucket_version
end

#nameString



49
50
51
# File 'lib/growthbook/inline_experiment.rb', line 49

def name
  @name
end

#namespaceString?



28
29
30
# File 'lib/growthbook/inline_experiment.rb', line 28

def namespace
  @namespace
end

#parent_conditionsArray<Hash>



67
68
69
# File 'lib/growthbook/inline_experiment.rb', line 67

def parent_conditions
  @parent_conditions
end

#phaseString?



52
53
54
# File 'lib/growthbook/inline_experiment.rb', line 52

def phase
  @phase
end

#rangesArray<Hash>



22
23
24
# File 'lib/growthbook/inline_experiment.rb', line 22

def ranges
  @ranges
end

#seedString?



46
47
48
# File 'lib/growthbook/inline_experiment.rb', line 46

def seed
  @seed
end

#variationsArray<String, Integer, Hash>



10
11
12
# File 'lib/growthbook/inline_experiment.rb', line 10

def variations
  @variations
end

#weightsArray<Float>



13
14
15
# File 'lib/growthbook/inline_experiment.rb', line 13

def weights
  @weights
end

Instance Method Details

#to_json(*_args) ⇒ Object



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/growthbook/inline_experiment.rb', line 97

def to_json(*_args)
  res = {}
  res['key'] = @key
  res['variations'] = @variations
  res['weights'] = @weights unless @weights.nil?
  res['active'] = @active if @active != true && !@active.nil?
  res['coverage'] = @coverage if @coverage != 1 && !@coverage.nil?
  res['ranges'] = @ranges
  res['condition'] = @condition
  res['namespace'] = @namespace
  res['force'] = @force unless @force.nil?
  res['hashAttribute'] = @hash_attribute if @hash_attribute != 'id' && !@hash_attribute.nil?
  res['hashVersion'] = @hash_version
  res['meta'] = @meta
  res['filters'] = @filters
  res['seed'] = @seed
  res['name'] = @name
  res['phase'] = @phase
  res['fallbackAttribute'] = @fallback_attribute unless @fallback_attribute.nil?
  res['disableStickyBucketing'] = @disable_sticky_bucketing if @disable_sticky_bucketing
  res['bucketVersion'] = @bucket_version if @bucket_version != 0
  res['minBucketVersion'] = @min_bucket_version if @min_bucket_version != 0
  res['parentConditions'] = @parent_conditions unless @parent_conditions.empty?

  res.compact
end