Class: Growthbook::FeatureResult

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

Overview

Result of a feature evaluation

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value, source, experiment, experiment_result) ⇒ FeatureResult

Returns a new instance of FeatureResult.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/growthbook/feature_result.rb', line 30

def initialize(
  value,
  source,
  experiment,
  experiment_result
)

  on = !value.nil? && value != 0 && value != '' && value != false

  @value = value
  @on = on
  @off = !on
  @source = source
  @experiment = experiment
  @experiment_result = experiment_result
end

Instance Attribute Details

#experimentGrowthbook::InlineExperiment? (readonly)

The experiment used to decide the feature value



24
25
26
# File 'lib/growthbook/feature_result.rb', line 24

def experiment
  @experiment
end

#experiment_resultGrowthbook::InlineExperimentResult? (readonly)

The result of the experiment



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

def experiment_result
  @experiment_result
end

#offBool (readonly)

Whether or not the feature is OFF

Returns:

  • (Bool)


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

def off
  @off
end

#onBool (readonly)

Whether or not the feature is ON

Returns:

  • (Bool)


12
13
14
# File 'lib/growthbook/feature_result.rb', line 12

def on
  @on
end

#sourceString (readonly)

The reason the feature was assigned this value

Returns:

  • (String)


20
21
22
# File 'lib/growthbook/feature_result.rb', line 20

def source
  @source
end

#valueAny? (readonly)

The assigned value of the feature

Returns:

  • (Any, nil)


8
9
10
# File 'lib/growthbook/feature_result.rb', line 8

def value
  @value
end

Instance Method Details

#to_json(*_args) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/growthbook/feature_result.rb', line 47

def to_json(*_args)
  json = {}
  json['on'] = @on
  json['off'] = @off
  json['value'] = @value
  json['source'] = @source

  if @experiment
    json['experiment'] = @experiment.to_json
    json['experimentResult'] = @experiment_result.to_json
  end

  json
end