Class: Fino::AbTesting::Experiment
- Inherits:
-
Object
- Object
- Fino::AbTesting::Experiment
- Includes:
- PrettyInspectable
- Defined in:
- lib/fino/ab_testing/experiment.rb
Constant Summary collapse
- TOTAL_PERCENTAGE =
100.0
Instance Attribute Summary collapse
-
#setting_definition ⇒ Object
readonly
Returns the value of attribute setting_definition.
Instance Method Summary collapse
- #<<(variant) ⇒ Object
-
#initialize(setting_definition) ⇒ Experiment
constructor
A new instance of Experiment.
- #value(for:) ⇒ Object
- #variant(for:) ⇒ Object
- #variants ⇒ Object
Methods included from PrettyInspectable
Constructor Details
#initialize(setting_definition) ⇒ Experiment
Returns a new instance of Experiment.
10 11 12 13 |
# File 'lib/fino/ab_testing/experiment.rb', line 10 def initialize(setting_definition) @setting_definition = setting_definition @user_variants = [] end |
Instance Attribute Details
#setting_definition ⇒ Object (readonly)
Returns the value of attribute setting_definition.
8 9 10 |
# File 'lib/fino/ab_testing/experiment.rb', line 8 def setting_definition @setting_definition end |
Instance Method Details
#<<(variant) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/fino/ab_testing/experiment.rb', line 15 def <<(variant) @user_variants << variant @variants = nil @value_by_variant_id = nil end |
#value(for:) ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/fino/ab_testing/experiment.rb', line 35 def value(for:) variant = variant(for: binding.local_variable_get(:for)) value_by_variant_id.fetch( variant.id, Fino::AbTesting::Variant::CONTROL_VALUE ) end |
#variant(for:) ⇒ Object
44 45 46 47 48 49 |
# File 'lib/fino/ab_testing/experiment.rb', line 44 def variant(for:) Fino::AbTesting::VariantPicker.new(setting_definition).call( variants, binding.local_variable_get(:for) ) end |
#variants ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/fino/ab_testing/experiment.rb', line 22 def variants return @variants if @variants return @variants = [] if @user_variants.empty? @variants = [ Fino::AbTesting::Variant.new( percentage: TOTAL_PERCENTAGE - @user_variants.sum(&:percentage), value: Fino::AbTesting::Variant::CONTROL_VALUE ), *@user_variants ] end |