class VWO::Services::SegmentEvaluator
Public Class Methods
Initializes this class with VWOLogger and OperandEvaluator
# File lib/vwo/services/segment_evaluator.rb, line 31 def initialize @logger = VWO::Logger.get_instance @operand_evaluator = OperandEvaluator.new end
Public Instance Methods
Evaluates the custom_variables passed against the pre-segmentation condition defined in the corresponding campaign.
@param :campaign_key Running_campaign's key @param :user_id Unique user identifier @param :dsl Segments provided in the settings_file @param :custom_variables Custom variables provided in the apis @param :disable_logs disable logs if True
@return true if user passed pre-segmentation, else false
# File lib/vwo/services/segment_evaluator.rb, line 70 def evaluate(campaign_key, user_id, dsl, custom_variables, disable_logs = false) result = evaluate_util(dsl, custom_variables) if valid_value?(dsl) result rescue StandardError => e @logger.log( LogLevelEnum::ERROR, format( LogMessageEnum::ErrorMessages::SEGMENTATION_ERROR, file: FileNameEnum::SegmentEvaluator, user_id: user_id, campaign_key: campaign_key, custom_variables: custom_variables, error_message: e ), disable_logs ) false end
A parser which recursively evaluates the expression tree represented by dsl, and returns the result
@param :dsl The segments defined in the campaign @param :custom_variables Key/value pair of custom_attributes properties
# File lib/vwo/services/segment_evaluator.rb, line 44 def evaluate_util(dsl, custom_variables) operator, sub_dsl = get_key_value(dsl) if operator == OperatorTypes::NOT !evaluate_util(sub_dsl, custom_variables) elsif operator == OperatorTypes::AND sub_dsl.all? { |y| evaluate_util(y, custom_variables) } elsif operator == OperatorTypes::OR sub_dsl.any? { |y| evaluate_util(y, custom_variables) } elsif operator == OperandTypes::CUSTOM_VARIABLE @operand_evaluator.evaluate_custom_variable?(sub_dsl, custom_variables) elsif operator == OperandTypes::USER @operand_evaluator.evaluate_user?(sub_dsl, custom_variables) end end