Class: FilterRename::Filters::Translate

Inherits:
FilterRename::FilterBase show all
Defined in:
lib/filter_rename/filters.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from FilterRename::FilterBase

#current_target, #get_config, #get_string, #get_words, #initialize, #match?, #set_config, #set_string, #wrap_regex

Constructor Details

This class inherits a constructor from FilterRename::FilterBase

Class Method Details

.hint ⇒ Object



1036
1037
1038
# File 'lib/filter_rename/filters.rb', line 1036

def self.hint
  "Replace text in GROUP from SUBGRPSRC to SUBGRPDST"
end

.params ⇒ Object



1040
1041
1042
# File 'lib/filter_rename/filters.rb', line 1040

def self.params
  "GROUP,SUBGRPSRC,SUBGRPDST"
end

Instance Method Details

#filter(params) ⇒ Object



1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
# File 'lib/filter_rename/filters.rb', line 1044

def filter(params)
  str = get_string
  group = params[0].to_sym
  lang_src = params[1] ? params[1].to_sym : :none
  lang_dest = params[2] ? params[2].to_sym : :none

  get_words(group, lang_src).each_with_index do |x, i|
    str = str.gsub(Regexp.new(x, get_config(:ignore_case)), get_words(group, lang_dest, i))
  end

  super(str)
end