Class: Speckle::List::PatternFilter

Inherits:
Object
  • Object
show all
Defined in:
lib/speckle/list/pattern_filter.rb

Instance Method Summary collapse

Constructor Details

#initialize(pattern, invert = false) ⇒ PatternFilter

Returns a new instance of PatternFilter.



4
5
6
7
# File 'lib/speckle/list/pattern_filter.rb', line 4

def initialize(pattern, invert = false)
  @pattern = pattern
  @invert = invert
end

Instance Method Details

#run(item) ⇒ Object



9
10
11
12
13
14
15
16
17
18
# File 'lib/speckle/list/pattern_filter.rb', line 9

def run(item)
  regex = Regexp.new(@pattern)
  matched = !item.match(regex).nil?
  if @invert
    matched = !matched
  end

  return [item] if matched
  return []
end