Sha256: a2dce17f3111b0082ae35cb78b11970f386fa51b2e214897b23c3c8d48337f43
Contents?: true
Size: 1.32 KB
Versions: 28
Compression:
Stored size: 1.32 KB
Contents
# frozen_string_literal: true module SplitIoClient class BetweenMatcher < Matcher MATCHER_TYPE = 'BETWEEN' attr_reader :attribute def initialize(attribute_hash) @attribute = attribute_hash[:attribute] @data_type = attribute_hash[:data_type] @start_value = formatted_value(attribute_hash[:start_value], true) @end_value = formatted_value(attribute_hash[:end_value], true) end def match?(args) SplitLogger.log_if_debug('[BetweenMatcher] evaluating value and attributes.') return false unless SplitIoClient::Validators.valid_matcher_arguments(args) value = formatted_value(args[:value] || args[:attributes][@attribute.to_sym]) SplitLogger.log_if_debug("[BetweenMatcher] Value from parameters: #{value}.") return false unless value.is_a?(Integer) matches = (@start_value..@end_value).cover? value SplitLogger.log_if_debug("[BetweenMatcher] is #{value} between #{@start_value} and #{@end_value} -> #{matches} .") matches end private def formatted_value(value, sdk_data = false) case @data_type when 'NUMBER' value when 'DATETIME' value /= 1000 if sdk_data SplitIoClient::Utilities.to_milis_zero_out_from_seconds(value) else @logger.error('Invalid data type') end end end end
Version data entries
28 entries across 28 versions & 1 rubygems