Class: Cleaner::FileFilter

Inherits:
Object
  • Object
show all
Defined in:
lib/cleaner/file_filter.rb

Constant Summary collapse

CONDITIONS =
[:after, :if, :smaller_than, :bigger_than]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ FileFilter

Returns a new instance of FileFilter.



7
8
9
10
# File 'lib/cleaner/file_filter.rb', line 7

def initialize(options = {})
  @options = options
  @pattern = options[:pattern]
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/cleaner/file_filter.rb', line 5

def options
  @options
end

Instance Method Details

#filterizeObject



12
13
14
15
# File 'lib/cleaner/file_filter.rb', line 12

def filterize
  paths = filter_by_name
  conditions_provided? ? filter_by_conditions(paths) : paths
end

#search_patternObject



17
18
19
20
21
22
23
24
# File 'lib/cleaner/file_filter.rb', line 17

def search_pattern
  case @pattern
    when NilClass; "#{path}/*"
    when String; "#{path}/#{@pattern}"
    when Symbol; "#{path}/*.#{@pattern}"
    when Array; @pattern.map { |ext| "#{path}/*.#{ext}" }
  end
end