Module: VWO::Utils::Feature

Includes:
CONSTANTS, Enums
Included in:
VWO
Defined in:
lib/vwo/utils/feature.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

Instance Method Summary collapse

Instance Method Details

#get_type_casted_feature_value(value, variable_type) ⇒ Object

Returns type casted value to given value type if possible. @param :value Value to type cast @param :variable_type Type to which value needs to be casted @return Type casted value if value can be type-casted



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/vwo/utils/feature.rb', line 30

def get_type_casted_feature_value(value, variable_type)
  # Check if type(value) is already equal to required variable_type
  return value if RUBY_VARIABLE_TYPES[variable_type].include?(value.class)

  return value.to_s if variable_type == VariableTypes::STRING

  return value.to_i if variable_type == VariableTypes::INTEGER

  return value.to_f if variable_type == VariableTypes::DOUBLE

  return !value || value == 0 ? false : true if variable_type == VariableTypes.BOOLEAN

  return value if variable_type == VariableTypes::JSON
rescue StandardError => e
  Logger.log(
    LogLevelEnum::ERROR,
    "unable to type cast variable value: #{e.message}",
    {
      '{file}' => FILE
    }
  )
  nil
end