Class: VWO::Services::SegmentEvaluator
- Inherits:
-
Object
- Object
- VWO::Services::SegmentEvaluator
- Includes:
- Enums, Utils::Function, Utils::Segment, Utils::Validations
- Defined in:
- lib/vwo/services/segment_evaluator.rb
Constant Summary
Constants included from CONSTANTS
CONSTANTS::API_VERSION, CONSTANTS::DEFAULT_EVENTS_PER_REQUEST, CONSTANTS::DEFAULT_REQUEST_TIME_INTERVAL, CONSTANTS::GOAL_TYPES, CONSTANTS::HTTPS_PROTOCOL, CONSTANTS::HTTP_PROTOCOL, CONSTANTS::LIBRARY_PATH, CONSTANTS::MAX_EVENTS_PER_REQUEST, CONSTANTS::MAX_RANGE, CONSTANTS::MAX_TRAFFIC_PERCENT, CONSTANTS::MAX_TRAFFIC_VALUE, CONSTANTS::MIN_EVENTS_PER_REQUEST, CONSTANTS::MIN_REQUEST_TIME_INTERVAL, CONSTANTS::PLATFORM, CONSTANTS::RUBY_VARIABLE_TYPES, CONSTANTS::SDK_NAME, CONSTANTS::SDK_VERSION, CONSTANTS::SEED_VALUE, CONSTANTS::STATUS_RUNNING, CONSTANTS::URL_NAMESPACE, CONSTANTS::VWO_DELIMITER
Constants included from Utils::Segment
Utils::Segment::GROUPING_PATTERN, Utils::Segment::WILDCARD_PATTERN
Instance Method Summary collapse
-
#evaluate(campaign_key, user_id, dsl, custom_variables, disable_logs = false) ⇒ Object
Evaluates the custom_variables passed against the pre-segmentation condition defined in the corresponding campaign.
-
#evaluate_util(dsl, custom_variables) ⇒ Object
A parser which recursively evaluates the expression tree represented by dsl, and returns the result.
-
#initialize ⇒ SegmentEvaluator
constructor
Initializes this class with VWOLogger and OperandEvaluator.
Methods included from Utils::Validations
#invalid_config_log, #valid_basic_data_type?, #valid_batch_event_settings, #valid_boolean?, #valid_config_log, #valid_goal?, #valid_hash?, #valid_number?, #valid_settings_file?, #valid_string?, #valid_value?, #validate_sdk_config?
Methods included from Utils::Segment
#convert_to_true_types, #process_custom_variables_value, #process_operand_value, #separate_operand
Methods included from Utils::Function
#get_current_unix_timestamp, #get_current_unix_timestamp_in_millis, #get_key_value, #get_random_number
Constructor Details
#initialize ⇒ SegmentEvaluator
Initializes this class with VWOLogger and OperandEvaluator
31 32 33 34 |
# File 'lib/vwo/services/segment_evaluator.rb', line 31 def initialize @logger = VWO::Utils::Logger @operand_evaluator = OperandEvaluator.new end |
Instance Method Details
#evaluate(campaign_key, user_id, dsl, custom_variables, disable_logs = false) ⇒ Object
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
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/vwo/services/segment_evaluator.rb', line 71 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, 'SEGMENTATION_ERROR', { '{file}' => FileNameEnum::SEGMENT_EVALUATOR, '{userId}' => user_id, '{campaignKey}' => campaign_key, '{variation}' => '', '{customVariables}' => custom_variables, '{err}' => e. }, disable_logs ) false end |
#evaluate_util(dsl, custom_variables) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/vwo/services/segment_evaluator.rb', line 44 def evaluate_util(dsl, custom_variables) operator, sub_dsl = get_key_value(dsl) case operator when OperatorTypes::NOT !evaluate_util(sub_dsl, custom_variables) when OperatorTypes::AND sub_dsl.all? { |y| evaluate_util(y, custom_variables) } when OperatorTypes::OR sub_dsl.any? { |y| evaluate_util(y, custom_variables) } when OperandTypes::CUSTOM_VARIABLE @operand_evaluator.evaluate_custom_variable?(sub_dsl, custom_variables) when OperandTypes::USER @operand_evaluator.evaluate_user?(sub_dsl, custom_variables) end end |