Class: Kameleoon::Configuration::Rule

Inherits:
Object
  • Object
show all
Defined in:
lib/kameleoon/configuration/rule.rb

Overview

Rule is a class for new rules of feature flags

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Rule

Returns a new instance of Rule.



23
24
25
26
27
28
29
# File 'lib/kameleoon/configuration/rule.rb', line 23

def initialize(hash)
  @type = hash['type']
  @exposition = hash['exposition']
  @experiment_id = hash['experimentId']
  @variation_by_exposition = VariationByExposition.create_from_array(hash['variationByExposition'])
  @targeting_segment = Kameleoon::Targeting::Segment.new((hash['segment'])) if hash['segment']
end

Instance Attribute Details

#experiment_idObject

Returns the value of attribute experiment_id.



17
18
19
# File 'lib/kameleoon/configuration/rule.rb', line 17

def experiment_id
  @experiment_id
end

#expositionObject

Returns the value of attribute exposition.



17
18
19
# File 'lib/kameleoon/configuration/rule.rb', line 17

def exposition
  @exposition
end

#targeting_segmentObject

Returns the value of attribute targeting_segment.



17
18
19
# File 'lib/kameleoon/configuration/rule.rb', line 17

def targeting_segment
  @targeting_segment
end

#typeObject

Returns the value of attribute type.



17
18
19
# File 'lib/kameleoon/configuration/rule.rb', line 17

def type
  @type
end

#variation_by_expositionObject

Returns the value of attribute variation_by_exposition.



17
18
19
# File 'lib/kameleoon/configuration/rule.rb', line 17

def variation_by_exposition
  @variation_by_exposition
end

Class Method Details

.create_from_array(array) ⇒ Object



19
20
21
# File 'lib/kameleoon/configuration/rule.rb', line 19

def self.create_from_array(array)
  array&.map { |it| Rule.new(it) }
end

Instance Method Details

#get_variation_id_by_key(key) ⇒ Object



40
41
42
# File 'lib/kameleoon/configuration/rule.rb', line 40

def get_variation_id_by_key(key)
  variation_by_exposition.select { |v| v.variation_key == key }.first&.variation_id
end

#get_variation_key(hash_double) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/kameleoon/configuration/rule.rb', line 31

def get_variation_key(hash_double)
  total = 0.0
  variation_by_exposition.each do |element|
    total += element.exposition
    return element.variation_key if total >= hash_double
  end
  nil
end