class VWO::Services::OperandEvaluator

Public Instance Methods

contains?(operand_value, custom_variables_value) click to toggle source

Checks if custom_variables_value contains operand_value

@param [String] :operand_value Leaf value from the segments @param [String] :custom_variables_value Value from the custom_variables

@return [Boolean]

# 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) click to toggle source

Checks if custom_variables_value starts with operand_value

@param [String] :operand_value Leaf value from the segments @param [String] :custom_variables_value Value from the custom_variables

@return [Boolean]

# 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) click to toggle source

Checks if both values are exactly same

@param [String] :operand_value Leaf value from the segments @param [String] :custom_variables_value Value from the custom_variables

@return [Boolean]

# 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) click to toggle source

Identifies the condition stated in the leaf node and evaluates the result

@param [String] :operand_value Leaf value from the segments @param [String] :custom_variables_value Value from the custom_variables

@return [Boolean]

# File lib/vwo/services/operand_evaluator.rb, line 92
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]

  # 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) click to toggle source
# File lib/vwo/services/operand_evaluator.rb, line 113
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
lower?(operand_value, custom_variables_value) click to toggle source

Checks if both values are same after 'down-casing' i.e. case insensitive check

@param [String] :operand_value Leaf value from the segments @param [String] :custom_variables_value Value from the custom_variables

@return [Boolean]

# 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) click to toggle source

Checks if custom_variables_value matches the regex specified by operand_value

@param [String] :operand_value Leaf value from the segments @param [String] :custom_variables_value Value from the custom_variables

@return [Boolean]

# 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) click to toggle source

Checks if custom_variables_value ends with operand_value

@param [String] :operand_value Leaf value from the segments @param [String] :custom_variables_value Value from the custom_variables

@return [Boolean]

# 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