Class: Featureflow::EvaluateHelpers
- Inherits:
-
Object
- Object
- Featureflow::EvaluateHelpers
- Defined in:
- lib/featureflow/evaluate_helpers.rb
Class Method Summary collapse
- .calculate_hash(salt = '1', feature = 'feature', key = 'anonymous') ⇒ Object
- .get_variant_split_key(variant_splits, variant_value) ⇒ Object
- .get_variant_value(hash) ⇒ Object
- .rule_matches(rule, user) ⇒ Object
Class Method Details
.calculate_hash(salt = '1', feature = 'feature', key = 'anonymous') ⇒ Object
28 29 30 |
# File 'lib/featureflow/evaluate_helpers.rb', line 28 def self.calculate_hash(salt = '1', feature = 'feature', key = 'anonymous') (Digest::SHA1.hexdigest [salt, feature, key].join(':'))[0..14]; end |
.get_variant_split_key(variant_splits, variant_value) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/featureflow/evaluate_helpers.rb', line 20 def self.get_variant_split_key(variant_splits, variant_value) percent = 0 variant_splits.each do |variant_split| percent += variant_split['split'] return variant_split['variantKey'] if percent >= variant_value end end |
.get_variant_value(hash) ⇒ Object
32 33 34 |
# File 'lib/featureflow/evaluate_helpers.rb', line 32 def self.get_variant_value(hash) Integer(hash, 16) % 100 + 1 end |
.rule_matches(rule, user) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/featureflow/evaluate_helpers.rb', line 6 def self.rule_matches(rule, user) if rule['defaultRule'] true # the default rule will always match true else rule['audience']['conditions'].all? do |condition| user_attributes = user[:attributes][condition['target']] # convert to array to work with test Array(user_attributes).any? do |attribute| Conditions.test condition['operator'], attribute, condition['values'] end end end end |