Class: Kybus::Configuration::FeatureFlag::ABTest
- Inherits:
-
Object
- Object
- Kybus::Configuration::FeatureFlag::ABTest
- Defined in:
- lib/kybus/configs/feature_flag/ab_test.rb
Direct Known Subclasses
Instance Method Summary collapse
- #active? ⇒ Boolean
-
#initialize(configs) ⇒ ABTest
constructor
A new instance of ABTest.
- #normalize_thershold(value) ⇒ Object
Constructor Details
#initialize(configs) ⇒ ABTest
Returns a new instance of ABTest.
7 8 9 10 |
# File 'lib/kybus/configs/feature_flag/ab_test.rb', line 7 def initialize(configs) @configs = configs @threshold = normalize_thershold(configs['threshold']) end |
Instance Method Details
#active? ⇒ Boolean
25 26 27 |
# File 'lib/kybus/configs/feature_flag/ab_test.rb', line 25 def active? rand <= @threshold end |
#normalize_thershold(value) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/kybus/configs/feature_flag/ab_test.rb', line 12 def normalize_thershold(value) case value when Integer raise 'Value out of range' unless (0..100).cover?(value) value.to_f / 100 when Float raise 'Value out of range' unless (0..1).cover?(value) value end end |