Class: SplitIoClient::EndsWithMatcher

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attribute, suffix_list) ⇒ EndsWithMatcher

Returns a new instance of EndsWithMatcher.



7
8
9
10
# File 'lib/engine/matchers/ends_with_matcher.rb', line 7

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

Class Method Details

.matcher_type ⇒ Object



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

def self.matcher_type
  'ENDS_WITH'.freeze
end

Instance Method Details

#match?(_key, data) ⇒ Boolean

Returns:

  • (Boolean)


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

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

  return false if @suffix_list.empty?

  @suffix_list.any? { |suffix| value.to_s.end_with? suffix }
end