Class: VWO::Services::OperandEvaluator
- Inherits:
-
Object
- Object
- VWO::Services::OperandEvaluator
- Includes:
- Utils::Function, Utils::Segment
- Defined in:
- lib/vwo/services/operand_evaluator.rb
Constant Summary
Constants included from Utils::Segment
Utils::Segment::GROUPING_PATTERN, Utils::Segment::WILDCARD_PATTERN
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
Instance Method Summary collapse
-
#contains?(operand_value, custom_variables_value) ⇒ Boolean
Checks if custom_variables_value contains operand_value.
-
#ends_with?(operand_value, custom_variables_value) ⇒ Boolean
Checks if custom_variables_value starts with operand_value.
-
#equals?(operand_value, custom_variables_value) ⇒ Boolean
Checks if both values are exactly same.
-
#evaluate_custom_variable?(operand, custom_variables) ⇒ Boolean
Identifies the condition stated in the leaf node and evaluates the result.
- #evaluate_user?(operand, custom_variables) ⇒ Boolean
-
#greater_than?(operand_value, custom_variables_value) ⇒ Boolean
Checks if custom_variable_value is greater than operand_value.
-
#greater_than_equal_to?(operand_value, custom_variables_value) ⇒ Boolean
Checks if custom_variable_value is greater than or equal to operand_value.
-
#less_than?(operand_value, custom_variables_value) ⇒ Boolean
True or False.
-
#less_than_equal_to?(operand_value, custom_variables_value) ⇒ Boolean
Checks if custom_variable_value is less than or equal to operand_value.
-
#lower?(operand_value, custom_variables_value) ⇒ Boolean
Checks if both values are same after ‘down-casing’ i.e.
-
#regex?(operand_value, custom_variables_value) ⇒ Boolean
Checks if custom_variables_value matches the regex specified by operand_value.
-
#starts_with?(operand_value, custom_variables_value) ⇒ Boolean
Checks if custom_variables_value ends with operand_value.
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
Instance Method Details
#contains?(operand_value, custom_variables_value) ⇒ Boolean
Checks if custom_variables_value contains operand_value
41 42 43 |
# File 'lib/vwo/services/operand_evaluator.rb', line 41 def contains?(operand_value, custom_variables_value) custom_variables_value.include?(operand_value) end |
#ends_with?(operand_value, custom_variables_value) ⇒ Boolean
Checks if custom_variables_value starts with operand_value
61 62 63 |
# File 'lib/vwo/services/operand_evaluator.rb', line 61 def ends_with?(operand_value, custom_variables_value) custom_variables_value.start_with?(operand_value) end |
#equals?(operand_value, custom_variables_value) ⇒ Boolean
Checks if both values are exactly same
82 83 84 |
# File 'lib/vwo/services/operand_evaluator.rb', line 82 def equals?(operand_value, custom_variables_value) custom_variables_value == operand_value end |
#evaluate_custom_variable?(operand, custom_variables) ⇒ Boolean
Identifies the condition stated in the leaf node and evaluates the result
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/vwo/services/operand_evaluator.rb', line 129 def evaluate_custom_variable?(operand, custom_variables) # Extract custom_variable_key and custom_variables_value from operand operand_key, operand = get_key_value(operand) # Retrieve corresponding custom_variable value from custom_variables custom_variables_value = custom_variables[operand_key.to_sym] # Pre process custom_variable value custom_variables_value = process_custom_variables_value(custom_variables_value) # Pre process operand value operand_type, operand_value = process_operand_value(operand) # Process the custom_variables_value and operand_value to make them of same type operand_value, custom_variables_value = convert_to_true_types(operand_value, custom_variables_value) # Call the self method corresponding to operand_type to evaluate the result public_send("#{operand_type}?", operand_value, custom_variables_value) end |
#evaluate_user?(operand, custom_variables) ⇒ Boolean
149 150 151 152 153 154 155 |
# File 'lib/vwo/services/operand_evaluator.rb', line 149 def evaluate_user?(operand, custom_variables) users = operand.split(',') users.each do |user| return true if user.strip == custom_variables[:_vwo_user_id] end false end |
#greater_than?(operand_value, custom_variables_value) ⇒ Boolean
Checks if custom_variable_value is greater than operand_value
100 101 102 |
# File 'lib/vwo/services/operand_evaluator.rb', line 100 def greater_than?(operand_value, custom_variables_value) custom_variables_value.to_f > operand_value.to_f end |
#greater_than_equal_to?(operand_value, custom_variables_value) ⇒ Boolean
Checks if custom_variable_value is greater than or equal to operand_value
118 119 120 |
# File 'lib/vwo/services/operand_evaluator.rb', line 118 def greater_than_equal_to?(operand_value, custom_variables_value) custom_variables_value.to_f >= operand_value.to_f end |
#less_than?(operand_value, custom_variables_value) ⇒ Boolean
Returns True or False.
91 92 93 |
# File 'lib/vwo/services/operand_evaluator.rb', line 91 def less_than?(operand_value, custom_variables_value) custom_variables_value.to_f < operand_value.to_f end |
#less_than_equal_to?(operand_value, custom_variables_value) ⇒ Boolean
Checks if custom_variable_value is less than or equal to operand_value
109 110 111 |
# File 'lib/vwo/services/operand_evaluator.rb', line 109 def less_than_equal_to?(operand_value, custom_variables_value) custom_variables_value.to_f <= operand_value.to_f end |
#lower?(operand_value, custom_variables_value) ⇒ Boolean
Checks if both values are same after ‘down-casing’ i.e. case insensitive check
31 32 33 |
# File 'lib/vwo/services/operand_evaluator.rb', line 31 def lower?(operand_value, custom_variables_value) operand_value.downcase == custom_variables_value.downcase end |
#regex?(operand_value, custom_variables_value) ⇒ Boolean
Checks if custom_variables_value matches the regex specified by operand_value
71 72 73 74 |
# File 'lib/vwo/services/operand_evaluator.rb', line 71 def regex?(operand_value, custom_variables_value) pattern = Regexp.new operand_value custom_variables_value =~ pattern end |
#starts_with?(operand_value, custom_variables_value) ⇒ Boolean
Checks if custom_variables_value ends with operand_value
51 52 53 |
# File 'lib/vwo/services/operand_evaluator.rb', line 51 def starts_with?(operand_value, custom_variables_value) custom_variables_value.end_with?(operand_value) end |