Class: Speckle::List::FileContentFilter
- Inherits:
-
Object
- Object
- Speckle::List::FileContentFilter
- Defined in:
- lib/speckle/list/file_content_filter.rb
Instance Method Summary collapse
- #has_content(item, pattern) ⇒ Object
-
#initialize(pattern, invert = false) ⇒ FileContentFilter
constructor
A new instance of FileContentFilter.
- #run(item) ⇒ Object
Constructor Details
#initialize(pattern, invert = false) ⇒ FileContentFilter
4 5 6 7 |
# File 'lib/speckle/list/file_content_filter.rb', line 4 def initialize(pattern, invert = false) @pattern = pattern @invert = invert end |
Instance Method Details
#has_content(item, pattern) ⇒ Object
21 22 23 24 |
# 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) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 |
# 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 |