Class: Rox::Core::RoxString
- Inherits:
-
Object
- Object
- Rox::Core::RoxString
- Defined in:
- lib/rox/core/entities/rox_string.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.
-
#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
- #external_type ⇒ Object
-
#initialize(default_value, options = []) ⇒ RoxString
constructor
A new instance of RoxString.
- #internal_value(context, nil_instead_of_default, evaluated_type = String) ⇒ Object
- #send_impressions(return_value, merged_context) ⇒ Object
- #set_for_evaluation(parser, experiment, impression_invoker) ⇒ Object
- #value(context = nil) ⇒ Object
Constructor Details
#initialize(default_value, options = []) ⇒ RoxString
Returns a new instance of RoxString.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/rox/core/entities/rox_string.rb', line 11 def initialize(default_value, = []) @default_value = default_value @options = .clone raise ArgumentError, 'options should be an array' unless .is_a?(Array) if .length > 0 && .any? { |x| x.class != default_value.class } raise ArgumentError, 'options should be the same type as default value' end @options << default_value unless .include?(default_value) @condition = nil @parser = 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/rox_string.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/rox_string.rb', line 8 def condition @condition end |
#default_value ⇒ Object
Returns the value of attribute default_value.
8 9 10 |
# File 'lib/rox/core/entities/rox_string.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/rox_string.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/rox_string.rb', line 8 def name @name end |
#options ⇒ Object
Returns the value of attribute options.
8 9 10 |
# File 'lib/rox/core/entities/rox_string.rb', line 8 def @options end |
#parser ⇒ Object
Returns the value of attribute parser.
8 9 10 |
# File 'lib/rox/core/entities/rox_string.rb', line 8 def parser @parser end |
Instance Method Details
#external_type ⇒ Object
67 68 69 |
# File 'lib/rox/core/entities/rox_string.rb', line 67 def external_type 'String' end |
#internal_value(context, nil_instead_of_default, evaluated_type = String) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/rox/core/entities/rox_string.rb', line 51 def internal_value(context, nil_instead_of_default, evaluated_type = String) return_value = nil_instead_of_default ? nil : @default_value merged_context = MergedContext.new(@parser&.global_context, context) unless @parser.nil? || @condition.nil? || @condition.empty? evaluation_result = @parser.evaluate_expression(@condition, merged_context) unless evaluation_result.nil? value = evaluated_type == String ? evaluation_result.string_value : evaluation_result.value is_empty = value.is_a?(String) && value.empty? return_value = value if !value.nil? && !is_empty end end return_value end |
#send_impressions(return_value, merged_context) ⇒ Object
27 28 29 30 |
# File 'lib/rox/core/entities/rox_string.rb', line 27 def send_impressions(return_value, merged_context) reporting_value = ReportingValue.new(@name, return_value, @client_experiment) @impression_invoker&.invoke(reporting_value, @client_experiment, merged_context) end |
#set_for_evaluation(parser, experiment, impression_invoker) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/rox/core/entities/rox_string.rb', line 32 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
45 46 47 48 49 |
# File 'lib/rox/core/entities/rox_string.rb', line 45 def value(context = nil) return_value = internal_value(context, false) send_impressions(return_value, context) return_value end |