Class: SplitIoClient::ContainsMatcher

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

Class Method 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/engine/matchers/contains_matcher.rb', line 7

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

Class Method Details

.matcher_type ⇒ Object



3
4
5
# File 'lib/engine/matchers/contains_matcher.rb', line 3

def self.matcher_type
  'CONTAINS_WITH'.freeze
end

Instance Method Details

#match?(_key, data) ⇒ Boolean

Returns:

  • (Boolean)


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

def match?(_key, data)
  value = data.fetch(@attribute) { |attr| data[attr.to_s] || data[attr.to_sym] }

  return false if @substr_list.empty?

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