Skip to content

Commit

Permalink
feat: Added support for numeric operators in targeting and whitelisting
Browse files Browse the repository at this point in the history
  • Loading branch information
sakshamg1304 authored and Varun Malhotra committed Aug 26, 2024
1 parent 4ee8a8c commit 793077c
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 1 deletion.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.41.0] - 2024-27-08

### Added

- Added support for handling the below operators in targeting and whitelisting i.e.

- Greater than
- Greater than equal to
- Less than
- Less than equal to

## [1.40.0] - 2024-04-08

### Added
Expand Down
2 changes: 1 addition & 1 deletion lib/vwo/constants.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module CONSTANTS
HTTP_PROTOCOL = 'http://'
HTTPS_PROTOCOL = 'https://'
URL_NAMESPACE = '6ba7b811-9dad-11d1-80b4-00c04fd430c8'
SDK_VERSION = '1.40.0'
SDK_VERSION = '1.41.0'
SDK_NAME = 'ruby'
VWO_DELIMITER = '_vwo_'
MAX_EVENTS_PER_REQUEST = 5000
Expand Down
8 changes: 8 additions & 0 deletions lib/vwo/enums.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ module OperandValueTypesName
WILDCARD = 'wildcard'
LOWER = 'lower'
EQUALS = 'equals'
GREATER_THAN="gt"
LESS_THAN="lt"
GREATER_THAN_EQUAL_TO="gte"
LESS_THAN_EQUAL_TO="lte"
end

module OperandValueTypes
Expand All @@ -30,6 +34,10 @@ module OperandValueTypes
ENDS_WITH = 'ends_with'
REGEX = 'regex'
EQUALS = 'equals'
LESS_THAN = 'less_than'
GREATER_THAN = 'greater_than'
LESS_THAN_EQUAL_TO = 'less_than_equal_to'
GREATER_THAN_EQUAL_TO = 'greater_than_equal_to'
end

module OperatorTypes
Expand Down
37 changes: 37 additions & 0 deletions lib/vwo/services/operand_evaluator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,43 @@ def equals?(operand_value, custom_variables_value)
custom_variables_value == operand_value
end

# Checks if custom_variables_value matches the regex specified by operand_value
#
# @param [String] operand_value Leaf value from the segments
# @param [Numeric] custom_variables_value Value from the custom_variables
# @return [Boolean] True or False
def less_than?(operand_value, custom_variables_value)
custom_variables_value.to_f < operand_value.to_f
end

# Checks if custom_variable_value is greater than operand_value
#
# @param [String] operand_value Leaf value from the segments
# @param [Numeric] custom_variables_value Value from the custom_variables
# @return [Boolean] True or False
def greater_than?(operand_value, custom_variables_value)
custom_variables_value.to_f > operand_value.to_f
end

# Checks if custom_variable_value is less than or equal to operand_value
#
# @param [String] operand_value Leaf value from the segments
# @param [Numeric] custom_variables_value Value from the custom_variables
# @return [Boolean] True or False
def less_than_equal_to?(operand_value, custom_variables_value)
custom_variables_value.to_f <= operand_value.to_f
end

# Checks if custom_variable_value is greater than or equal to operand_value
#
# @param [String] operand_value Leaf value from the segments
# @param [Numeric] custom_variables_value Value from the custom_variables
# @return [Boolean] True or False
def greater_than_equal_to?(operand_value, custom_variables_value)
custom_variables_value.to_f >= operand_value.to_f
end


# Identifies the condition stated in the leaf node and evaluates the result
#
# @param [String] :operand_value Leaf value from the segments
Expand Down
8 changes: 8 additions & 0 deletions lib/vwo/utils/segment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,14 @@ def process_operand_value(operand)
else
OperandValueTypes::EQUALS
end
elsif operand_type_name == OperandValueTypesName::GREATER_THAN
operand_type = OperandValueTypes::GREATER_THAN
elsif operand_type_name == OperandValueTypesName::LESS_THAN
operand_type = OperandValueTypes::LESS_THAN
elsif operand_type_name == OperandValueTypesName::GREATER_THAN_EQUAL_TO
operand_type = OperandValueTypes::GREATER_THAN_EQUAL_TO
elsif operand_type_name == OperandValueTypesName::LESS_THAN_EQUAL_TO
operand_type = OperandValueTypes::LESS_THAN_EQUAL_TO
end

# In case there is an abnormal patter, it would have passed all the above if cases, which means it
Expand Down

0 comments on commit 793077c

Please sign in to comment.