module Fixnames::Helpers

Public Instance Methods

match_bracket_close() click to toggle source
# File lib/fixnames/helpers.rb, line 40
def match_bracket_close
  "[#{Regexp.escape(option.bracket_characters_close)}]"
end
match_bracket_open() click to toggle source
# File lib/fixnames/helpers.rb, line 36
def match_bracket_open
  "[#{Regexp.escape(option.bracket_characters_open)}]"
end
remove(re) click to toggle source
# File lib/fixnames/helpers.rb, line 17
def remove(re)
  re_str = bold "/#{re}/"
  debug "\t<expunge>  #{re_str}"
  fixed.gsub! Regexp.new(re), ''
end
remove_all(condition) click to toggle source
# File lib/fixnames/helpers.rb, line 27
def remove_all(condition)
  safeloop(condition) { remove(condition) }
end
remove_bracket_characters_from(str) click to toggle source
# File lib/fixnames/helpers.rb, line 52
def remove_bracket_characters_from(str)
  str.gsub /(#{match_bracket_open}|#{match_bracket_close})/, ''
end
remove_bracket_ranges(re) click to toggle source
# File lib/fixnames/helpers.rb, line 48
def remove_bracket_ranges(re)
  remove wrap_brackets(".*?#{re}.*?")
end
replace(re, replacement) click to toggle source
# File lib/fixnames/helpers.rb, line 10
def replace(re, replacement)
  re_str = bold "/#{re}/"
  replacement_str = bold "\"#{replacement}\""
  debug "\t<replace>  #{re_str}  ->  #{replacement_str}"
  fixed.gsub! Regexp.new(re), replacement
end
replace_all(condition, replacement) click to toggle source
# File lib/fixnames/helpers.rb, line 23
def replace_all(condition, replacement)
  safeloop(condition) { replace(condition, replacement) }
end
safeloop(condition, max_tries = option.max_filter_loops, &block) click to toggle source
# File lib/fixnames/helpers.rb, line 3
def safeloop(condition, max_tries = option.max_filter_loops, &block)
  max_tries.times do
    return fixed unless fixed =~ Regexp.new(condition)
    block.call
  end
end
translate(src, dst) click to toggle source
# File lib/fixnames/helpers.rb, line 31
def translate(src, dst)
  debug "\t<translate>  #{bold src.inspect}  ->  #{bold dst.inspect}"
  fixed.tr! src, dst
end
wrap_brackets(re) click to toggle source
# File lib/fixnames/helpers.rb, line 44
def wrap_brackets(re)
  "#{match_bracket_open}#{re}#{match_bracket_close}"
end