Class: FilterRename::FilterPipe

Inherits:
Object
  • Object
show all
Defined in:
lib/filter_rename/filter_pipe.rb

Overview

Class that handles the filters applying them one after one.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fname, filters, cfg) ⇒ FilterPipe

Returns a new instance of FilterPipe.



11
12
13
14
15
16
17
18
# File 'lib/filter_rename/filter_pipe.rb', line 11

def initialize(fname, filters, cfg)
  # Filter params have to be reset for each file
  @cfg = cfg.filter.clone
  @source = FilenameFactory.create(fname, cfg.global)
  @dest = Marshal.load(Marshal.dump(@source))
  @filters = filters.instance_of?(Array) ? filters : filters.filters
  @words = cfg.words
end

Instance Attribute Details

#destObject (readonly)

Returns the value of attribute dest.



9
10
11
# File 'lib/filter_rename/filter_pipe.rb', line 9

def dest
  @dest
end

#sourceObject (readonly)

Returns the value of attribute source.



9
10
11
# File 'lib/filter_rename/filter_pipe.rb', line 9

def source
  @source
end

Instance Method Details

#applyObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/filter_rename/filter_pipe.rb', line 33

def apply
  @filters.each_with_index do |f, _i|
    filter = f.keys.pop
    params = f.values.pop

    if [FilterRename::Filters::Config, FilterRename::Filters::Select].include? filter
      filter.new(@dest, cfg: @cfg, words: @words).filter(params)
    else
      filter.new(@dest, cfg: @cfg, words: @words).filter(params) unless skip?
    end
  end

  self
end

#changed?Boolean

Returns:



20
21
22
# File 'lib/filter_rename/filter_pipe.rb', line 20

def changed?
  !unchanged?
end

#diffObject



29
30
31
# File 'lib/filter_rename/filter_pipe.rb', line 29

def diff
  @source.diff(@dest)
end

#rename!Object



48
49
50
# File 'lib/filter_rename/filter_pipe.rb', line 48

def rename!
  @source.rename!(@dest)
end

#unchanged?Boolean Also known as: identical?

Returns:



24
25
26
# File 'lib/filter_rename/filter_pipe.rb', line 24

def unchanged?
  @source == @dest
end