Class: Rox::Core::Variant
- Inherits:
-
Object
- Object
- Rox::Core::Variant
- Defined in:
- lib/rox/core/entities/variant.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#client_experiment ⇒ Object
Returns the value of attribute client_experiment.
-
#condition ⇒ Object
Returns the value of attribute condition.
-
#context ⇒ Object
Returns the value of attribute context.
-
#default_value ⇒ Object
Returns the value of attribute default_value.
-
#impression_invoker ⇒ Object
Returns the value of attribute impression_invoker.
-
#name ⇒ Object
Returns the value of attribute name.
-
#options ⇒ Object
Returns the value of attribute options.
-
#parser ⇒ Object
Returns the value of attribute parser.
Instance Method Summary collapse
-
#initialize(default_value, options) ⇒ Variant
constructor
A new instance of Variant.
- #set_for_evaluation(parser, experiment, impression_invoker) ⇒ Object
- #value(context = nil) ⇒ Object
Constructor Details
#initialize(default_value, options) ⇒ Variant
Returns a new instance of Variant.
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/rox/core/entities/variant.rb', line 10 def initialize(default_value, ) @default_value = default_value = .clone << default_value unless .include?(default_value) @condition = nil @parser = nil @context = nil @impression_invoker = nil @client_experiment = nil @name = nil end |
Instance Attribute Details
#client_experiment ⇒ Object
Returns the value of attribute client_experiment.
8 9 10 |
# File 'lib/rox/core/entities/variant.rb', line 8 def client_experiment @client_experiment end |
#condition ⇒ Object
Returns the value of attribute condition.
8 9 10 |
# File 'lib/rox/core/entities/variant.rb', line 8 def condition @condition end |
#context ⇒ Object
Returns the value of attribute context.
8 9 10 |
# File 'lib/rox/core/entities/variant.rb', line 8 def context @context end |
#default_value ⇒ Object
Returns the value of attribute default_value.
8 9 10 |
# File 'lib/rox/core/entities/variant.rb', line 8 def default_value @default_value end |
#impression_invoker ⇒ Object
Returns the value of attribute impression_invoker.
8 9 10 |
# File 'lib/rox/core/entities/variant.rb', line 8 def impression_invoker @impression_invoker end |
#name ⇒ Object
Returns the value of attribute name.
8 9 10 |
# File 'lib/rox/core/entities/variant.rb', line 8 def name @name end |
#options ⇒ Object
Returns the value of attribute options.
8 9 10 |
# File 'lib/rox/core/entities/variant.rb', line 8 def end |
#parser ⇒ Object
Returns the value of attribute parser.
8 9 10 |
# File 'lib/rox/core/entities/variant.rb', line 8 def parser @parser end |
Instance Method Details
#set_for_evaluation(parser, experiment, impression_invoker) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/rox/core/entities/variant.rb', line 23 def set_for_evaluation(parser, experiment, impression_invoker) if experiment.nil? @client_experiment = nil @condition = '' else @client_experiment = Experiment.new(experiment) @condition = experiment.condition end @parser = parser @impression_invoker = impression_invoker end |
#value(context = nil) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/rox/core/entities/variant.rb', line 36 def value(context = nil) return_value = @default_value merged_context = MergedContext.new(@context, context) if !@parser.nil? && !@condition.nil? && !@condition.empty? evaluation_result = @parser.evaluate_expression(@condition, merged_context) unless evaluation_result.nil? value = evaluation_result.string_value if !value.nil? && !value.empty? return_value = value if .include?(value) end end end @impression_invoker.invoke(ReportingValue.new(@name, return_value), @client_experiment, merged_context) if @impression_invoker != nil return_value end |