Class: Ant::Configuration::FeatureFlag::ABTest
- Inherits:
-
Object
- Object
- Ant::Configuration::FeatureFlag::ABTest
- Defined in:
- lib/ant/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.
5 6 7 8 9 |
# File 'lib/ant/configs/feature_flag/ab_test.rb', line 5 def initialize(configs) @configs = configs @threshold = normalize_thershold(configs['threshold']) end |
Instance Method Details
#active? ⇒ Boolean
24 25 26 |
# File 'lib/ant/configs/feature_flag/ab_test.rb', line 24 def active? rand <= @threshold end |
#normalize_thershold(value) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/ant/configs/feature_flag/ab_test.rb', line 11 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 |