Class: Kameleoon::Configuration::Rule
- Inherits:
-
Object
- Object
- Kameleoon::Configuration::Rule
- Defined in:
- lib/kameleoon/configuration/rule.rb
Overview
Rule is a class for new rules of feature flags
Instance Attribute Summary collapse
-
#experiment_id ⇒ Object
readonly
Returns the value of attribute experiment_id.
-
#exposition ⇒ Object
readonly
Returns the value of attribute exposition.
-
#first_variation ⇒ Object
readonly
Returns the value of attribute first_variation.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#order ⇒ Object
readonly
Returns the value of attribute order.
-
#respool_time ⇒ Object
readonly
Returns the value of attribute respool_time.
-
#segment_id ⇒ Object
readonly
Returns the value of attribute segment_id.
-
#targeting_segment ⇒ Object
Returns the value of attribute targeting_segment.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#variation_by_exposition ⇒ Object
readonly
Returns the value of attribute variation_by_exposition.
Class Method Summary collapse
Instance Method Summary collapse
- #experimentation_type? ⇒ Boolean
- #get_variation(hash_double) ⇒ Object
- #get_variation_by_key(variation_key) ⇒ Object
- #get_variation_id_by_key(key) ⇒ Object
-
#initialize(hash) ⇒ Rule
constructor
A new instance of Rule.
- #targeted_delivery_type? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(hash) ⇒ Rule
Returns a new instance of Rule.
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/kameleoon/configuration/rule.rb', line 45 def initialize(hash) @id = hash['id'] @order = hash['order'] @type = RuleType.from_literal(hash['type']) @exposition = hash['exposition'] @experiment_id = hash['experimentId'] @respool_time = hash['respoolTime'] @variation_by_exposition = VariationByExposition.create_from_array(hash['variationByExposition']) @variation_by_exposition.freeze @first_variation = @variation_by_exposition.first @targeting_segment = Kameleoon::Targeting::Segment.new((hash['segment'])) if hash['segment'] @segment_id = @targeting_segment != nil ? targeting_segment.id : -1 end |
Instance Attribute Details
#experiment_id ⇒ Object (readonly)
Returns the value of attribute experiment_id.
33 34 35 |
# File 'lib/kameleoon/configuration/rule.rb', line 33 def experiment_id @experiment_id end |
#exposition ⇒ Object (readonly)
Returns the value of attribute exposition.
33 34 35 |
# File 'lib/kameleoon/configuration/rule.rb', line 33 def exposition @exposition end |
#first_variation ⇒ Object (readonly)
Returns the value of attribute first_variation.
33 34 35 |
# File 'lib/kameleoon/configuration/rule.rb', line 33 def first_variation @first_variation end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
33 34 35 |
# File 'lib/kameleoon/configuration/rule.rb', line 33 def id @id end |
#order ⇒ Object (readonly)
Returns the value of attribute order.
33 34 35 |
# File 'lib/kameleoon/configuration/rule.rb', line 33 def order @order end |
#respool_time ⇒ Object (readonly)
Returns the value of attribute respool_time.
33 34 35 |
# File 'lib/kameleoon/configuration/rule.rb', line 33 def respool_time @respool_time end |
#segment_id ⇒ Object (readonly)
Returns the value of attribute segment_id.
33 34 35 |
# File 'lib/kameleoon/configuration/rule.rb', line 33 def segment_id @segment_id end |
#targeting_segment ⇒ Object
Returns the value of attribute targeting_segment.
35 36 37 |
# File 'lib/kameleoon/configuration/rule.rb', line 35 def targeting_segment @targeting_segment end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
33 34 35 |
# File 'lib/kameleoon/configuration/rule.rb', line 33 def type @type end |
#variation_by_exposition ⇒ Object (readonly)
Returns the value of attribute variation_by_exposition.
33 34 35 |
# File 'lib/kameleoon/configuration/rule.rb', line 33 def variation_by_exposition @variation_by_exposition end |
Class Method Details
Instance Method Details
#experimentation_type? ⇒ Boolean
81 82 83 |
# File 'lib/kameleoon/configuration/rule.rb', line 81 def experimentation_type? @type == RuleType::EXPERIMENTATION end |
#get_variation(hash_double) ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'lib/kameleoon/configuration/rule.rb', line 59 def get_variation(hash_double) total = 0.0 variation_by_exposition.each do |var_by_exp| total += var_by_exp.exposition return var_by_exp if total >= hash_double end nil end |
#get_variation_by_key(variation_key) ⇒ Object
68 69 70 71 72 73 74 75 |
# File 'lib/kameleoon/configuration/rule.rb', line 68 def get_variation_by_key(variation_key) var_by_exp = variation_by_exposition.find { |v| v.variation_key == variation_key } unless var_by_exp raise Exception::FeatureVariationNotFound.new(variation_key), "#{self} does not contain variation '#{variation_key}'" end var_by_exp end |
#get_variation_id_by_key(key) ⇒ Object
77 78 79 |
# File 'lib/kameleoon/configuration/rule.rb', line 77 def get_variation_id_by_key(key) variation_by_exposition.select { |v| v.variation_key == key }.first&.variation_id end |
#targeted_delivery_type? ⇒ Boolean
85 86 87 |
# File 'lib/kameleoon/configuration/rule.rb', line 85 def targeted_delivery_type? @type == RuleType::TARGETED_DELIVERY end |
#to_s ⇒ Object
41 42 43 |
# File 'lib/kameleoon/configuration/rule.rb', line 41 def to_s "Rule{id:#{@id}}" end |