class FilterRename::FilterPipe
Attributes
dest[R]
source[R]
Public Class Methods
new(fname, filters, cfg)
click to toggle source
# File lib/filter_rename/filter_pipe.rb, line 6 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.class == Array) ? filters : filters.filters @words = cfg.words end
Public Instance Methods
apply()
click to toggle source
# File lib/filter_rename/filter_pipe.rb, line 28 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?()
click to toggle source
# File lib/filter_rename/filter_pipe.rb, line 15 def changed? ! unchanged? end
diff()
click to toggle source
# File lib/filter_rename/filter_pipe.rb, line 24 def diff @source.diff(@dest) end
rename!()
click to toggle source
# File lib/filter_rename/filter_pipe.rb, line 46 def rename! @source.rename!(@dest) end
unchanged?()
click to toggle source
# File lib/filter_rename/filter_pipe.rb, line 19 def unchanged? @source == @dest end
Also aliased as: identical?
Private Instance Methods
skip?()
click to toggle source
# File lib/filter_rename/filter_pipe.rb, line 52 def skip? if [:full_filename, :full_path, :filename].include? @cfg.grep_target.to_sym unmatched = instance_variable_get('@' + @cfg.grep_on.to_s).send(@cfg.grep_target.to_sym).match(Regexp.new(@cfg.grep)).nil? else unmatched = instance_variable_get('@' + @cfg.grep_on.to_s).get_string(@cfg.grep_target).match(Regexp.new(@cfg.grep)).nil? end @cfg.grep_exclude.to_s.to_boolean ? !unmatched : unmatched end