Class: SplitIoClient::MatchesStringMatcher

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

Constant Summary collapse

MATCHER_TYPE =
'MATCHES_STRING'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attribute, regexp_string, logger) ⇒ MatchesStringMatcher

Returns a new instance of MatchesStringMatcher.



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

def initialize(attribute, regexp_string, logger)
  @attribute = attribute
  @regexp_string = @regexp_string.is_a?(Regexp) ? regexp_string : Regexp.new(regexp_string)
  @logger = logger
end

Instance Attribute Details

#attributeObject (readonly)

Returns the value of attribute attribute.



7
8
9
# File 'lib/splitclient-rb/engine/matchers/matches_string_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
# File 'lib/splitclient-rb/engine/matchers/matches_string_matcher.rb', line 15

def match?(args)
  value = args[:value] || args[:attributes].fetch(@attribute) do |a|
    args[:attributes][a.to_s] || args[:attributes][a.to_sym]
  end

  matches = !(value =~ @regexp_string).nil?
  @logger.log_if_debug("[MatchesStringMatcher] #{value} matches #{@regexp_string} -> #{matches}")
  matches
end

#string_type?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/splitclient-rb/engine/matchers/matches_string_matcher.rb', line 25

def string_type?
  true
end