Class: Growthbook::InlineExperimentResult

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

Overview

Result of running an experiment.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ InlineExperimentResult

Returns a new instance of InlineExperimentResult.



42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/growthbook/inline_experiment_result.rb', line 42

def initialize(options = {})
  @key = options[:key]
  @in_experiment = options[:in_experiment]
  @variation_id = options[:variation_id]
  @value = options[:value]
  @hash_used = options[:hash_used]
  @hash_attribute = options[:hash_attribute]
  @hash_value = options[:hash_value]
  @feature_id = options[:feature_id]
  @bucket = options[:bucket]
  @name = options[:name]
  @passthrough = options[:passthrough]
  @sticky_bucket_used = options[:sticky_bucket_used]
end

Instance Attribute Details

#bucketFloat (readonly)

Returns The hash value used to assign a variation (float from 0 to 1).

Returns:

  • (Float)

    The hash value used to assign a variation (float from 0 to 1)



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

def bucket
  @bucket
end

#feature_idString? (readonly)

Returns The id of the feature (if any) that the experiment came from.

Returns:

  • (String, nil)

    The id of the feature (if any) that the experiment came from



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

def feature_id
  @feature_id
end

#hash_attributeString (readonly)

Returns The user attribute used to assign a variation.

Returns:

  • (String)

    The user attribute used to assign a variation



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

def hash_attribute
  @hash_attribute
end

#hash_usedBool (readonly)

Returns If a hash was used to assign a variation.

Returns:

  • (Bool)

    If a hash was used to assign a variation



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

def hash_used
  @hash_used
end

#hash_valueString (readonly)

Returns The value of that attribute.

Returns:

  • (String)

    The value of that attribute



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

def hash_value
  @hash_value
end

#in_experimentBoolean (readonly)

Returns Whether or not the user is part of the experiment.

Returns:

  • (Boolean)

    Whether or not the user is part of the experiment



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

def in_experiment
  @in_experiment
end

#keyString (readonly)

Returns The unique key for the assigned variation.

Returns:

  • (String)

    The unique key for the assigned variation



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

def key
  @key
end

#nameString? (readonly)

Returns Human-readable name for the experiment.

Returns:

  • (String, nil)

    Human-readable name for the experiment



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

def name
  @name
end

#passthroughBoolean

Returns Used for holdout groups.

Returns:

  • (Boolean)

    Used for holdout groups



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

def passthrough
  @passthrough
end

#sticky_bucket_usedBoolean

Returns When true, sticky bucketing was used to assign a variation.

Returns:

  • (Boolean)

    When true, sticky bucketing was used to assign a variation



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

def sticky_bucket_used
  @sticky_bucket_used
end

#valueAny (readonly)

Returns The array value of the assigned variation.

Returns:

  • (Any)

    The array value of the assigned variation



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

def value
  @value
end

#variation_idInteger (readonly)

Returns The array index of the assigned variation.

Returns:

  • (Integer)

    The array index of the assigned variation



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

def variation_id
  @variation_id
end

Instance Method Details

#hash_used?Bool

If the variation was randomly assigned based on user attribute hashes

Returns:

  • (Bool)


59
60
61
# File 'lib/growthbook/inline_experiment_result.rb', line 59

def hash_used?
  @hash_used
end

#in_experiment?Bool

Whether or not the user is in the experiment

Returns:

  • (Bool)


69
70
71
# File 'lib/growthbook/inline_experiment_result.rb', line 69

def in_experiment?
  @in_experiment
end

#sticky_bucket_used?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/growthbook/inline_experiment_result.rb', line 63

def sticky_bucket_used?
  @sticky_bucket_used || false
end

#to_json(*_args) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/growthbook/inline_experiment_result.rb', line 73

def to_json(*_args)
  {
    'inExperiment'     => @in_experiment,
    'variationId'      => @variation_id,
    'value'            => @value,
    'hashUsed'         => @hash_used,
    'hashAttribute'    => @hash_attribute,
    'hashValue'        => @hash_value,
    'featureId'        => @feature_id.to_s,
    'key'              => @key.to_s,
    'bucket'           => @bucket,
    'name'             => @name,
    'passthrough'      => @passthrough,
    'stickyBucketUsed' => @sticky_bucket_used
  }.compact
end