class Speckle::List::FileContentFilter

Public Class Methods

new(pattern, invert = false) click to toggle source
# File lib/speckle/list/file_content_filter.rb, line 4
def initialize(pattern, invert = false)
  @pattern = pattern
  @invert = invert
end

Public Instance Methods

has_content(item, pattern) click to toggle source
# File lib/speckle/list/file_content_filter.rb, line 21
def has_content(item, pattern)
  regex = Regexp.new(pattern)
  File.readlines(item).grep(regex).size > 0
end
run(item) click to toggle source
# File lib/speckle/list/file_content_filter.rb, line 9
def run(item)
  return [] unless File.exists?(item)

  matched = has_content(item, @pattern)
  if @invert
    matched = !matched
  end

  return [item] if matched
  return []
end