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, rule_id = '') ⇒ FeatureResult

Returns a new instance of FeatureResult.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/growthbook/feature_result.rb', line 34

def initialize(
  value,
  source,
  experiment,
  experiment_result,
  rule_id = ''
)

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

  @value = value
  @on = on
  @off = !on
  @source = source
  @experiment = experiment
  @experiment_result = experiment_result
  @rule_id = rule_id || ''
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

#rule_idString (readonly)

The id of the rule (if any) that was used to assign the value

Returns:

  • (String)


32
33
34
# File 'lib/growthbook/feature_result.rb', line 32

def rule_id
  @rule_id
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



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/growthbook/feature_result.rb', line 53

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

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

  json
end