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) ⇒ EqualToMatcher

Returns a new instance of EqualToMatcher.



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

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

Instance Attribute Details

#attribute ⇒ Object (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)


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

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

  return false unless SplitIoClient::Validators.valid_matcher_arguments(args)

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

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