Class: SplitIoClient::ContainsMatcher

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

Constant Summary collapse

MATCHER_TYPE =
'CONTAINS_WITH'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attribute, substr_list) ⇒ ContainsMatcher

Returns a new instance of ContainsMatcher.



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

def initialize(attribute, substr_list)
  @attribute = attribute
  @substr_list = substr_list
end

Instance Attribute Details

#attributeObject (readonly)

Returns the value of attribute attribute.



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

def attribute
  @attribute
end

Instance Method Details

#match?(args) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/splitclient-rb/engine/matchers/contains_matcher.rb', line 12

def match?(args)
  return false if !args.key?(:attributes) && !args.key?(:value)
  return false if args.key?(:value) && args[:value].nil?
  return false if args.key?(:attributes) && args[:attributes].nil?

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

  return false if @substr_list.empty?

  @substr_list.any? { |substr| value.to_s.include? substr }
end

#string_type?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/splitclient-rb/engine/matchers/contains_matcher.rb', line 26

def string_type?
  true
end