Class: FilterRename::FilterBase

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

Instance Method Summary collapse

Constructor Details

#initialize(obj, options) ⇒ FilterBase

Returns a new instance of FilterBase.



42
43
44
45
46
47
# File 'lib/filter_rename/filter_base.rb', line 42

def initialize(obj, options)
  super obj
  @dest = obj # useful for macros
  @cfg = options[:cfg]
  @words = options[:words]
end

Instance Method Details

#current_targetObject



94
95
96
# File 'lib/filter_rename/filter_base.rb', line 94

def current_target
  @cfg.target.to_s
end

#filter(value) ⇒ Object



65
66
67
# File 'lib/filter_rename/filter_base.rb', line 65

def filter(value)
  set_string value
end

#get_config(name) ⇒ Object



59
60
61
62
63
# File 'lib/filter_rename/filter_base.rb', line 59

def get_config(name)
  raise InvalidFilterSetting, name unless @cfg.instance_variables.include?("@#{name}".to_sym)

  @cfg.instance_variable_get '@' + name.to_s
end

#get_string(target = nil) ⇒ Object



77
78
79
80
81
82
83
# File 'lib/filter_rename/filter_base.rb', line 77

def get_string(target = nil)
  if target.nil?
    super @cfg.target
  else
    super target
  end
end

#get_words(name, section, idx = nil) ⇒ Object



49
50
51
# File 'lib/filter_rename/filter_base.rb', line 49

def get_words(name, section, idx = nil)
  @words.get_words name, section, idx
end

#match?(mask) ⇒ Boolean

Returns:



85
86
87
# File 'lib/filter_rename/filter_base.rb', line 85

def match?(mask)
  get_string =~ Regexp.new(mask)
end

#set_config(name, value) ⇒ Object



53
54
55
56
57
# File 'lib/filter_rename/filter_base.rb', line 53

def set_config(name, value)
  raise InvalidFilterSetting, name unless @cfg.instance_variables.include?("@#{name}".to_sym)

  @cfg.instance_variable_set ('@' + name.to_s), value
end

#set_string(value, target = nil) ⇒ Object



69
70
71
72
73
74
75
# File 'lib/filter_rename/filter_base.rb', line 69

def set_string(value, target = nil)
  if target.nil?
    super @cfg.target, value
  else
    super target, value
  end unless value.nil?
end

#wrap_regex(str) ⇒ Object



89
90
91
92
# File 'lib/filter_rename/filter_base.rb', line 89

def wrap_regex(str)
  str = "(#{str})" unless str =~ /\(.*\)/
  str
end