Class: SplitIoClient::EqualToMatcher

Inherits:
Matcher
  • Object
show all
Defined in:
lib/splitclient-rb/engine/matchers/equal_to_matcher.rb

Constant Summary collapse

MATCHER_TYPE =
'EQUAL_TO'

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Matcher

#equals?, #string_type?

Constructor Details

#initialize(attribute_hash, logger, validator) ⇒ EqualToMatcher

Returns a new instance of EqualToMatcher.



9
10
11
12
13
14
15
# File 'lib/splitclient-rb/engine/matchers/equal_to_matcher.rb', line 9

def initialize(attribute_hash, logger, validator)
  super(logger)
  @validator = validator
  @attribute = attribute_hash[:attribute]
  @data_type = attribute_hash[:data_type]
  @value = formatted_value(attribute_hash[:value], true)
end

Instance Attribute Details

#attributeObject (readonly)

Returns the value of attribute attribute.



7
8
9
# File 'lib/splitclient-rb/engine/matchers/equal_to_matcher.rb', line 7

def attribute
  @attribute
end

Instance Method Details

#match?(args) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
20
21
22
23
24
25
26
27
# File 'lib/splitclient-rb/engine/matchers/equal_to_matcher.rb', line 17

def match?(args)
  @logger.log_if_debug('[EqualsToMatcher] evaluating value and attributes.')

  return false unless @validator.valid_matcher_arguments(args)

  value = formatted_value(args[:value] || args[:attributes][@attribute.to_sym])

  matches = value.is_a?(Integer) ? (value == @value) : false
  @logger.log_if_debug("[EqualsToMatcher] #{value} equals to #{@value} -> #{matches}")
  matches
end