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'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attribute, regexp_string) ⇒ MatchesStringMatcher

Returns a new instance of MatchesStringMatcher.



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

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

Instance Attribute Details

#attributeObject (readonly)

Returns the value of attribute attribute.



5
6
7
# File 'lib/splitclient-rb/engine/matchers/matches_string_matcher.rb', line 5

def attribute
  @attribute
end

Instance Method Details

#match?(args) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
15
16
17
18
# File 'lib/splitclient-rb/engine/matchers/matches_string_matcher.rb', line 12

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

  (value =~ @regexp_string) != nil
end

#string_type?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/splitclient-rb/engine/matchers/matches_string_matcher.rb', line 20

def string_type?
  true
end