class Fixnames::Option

Constants

CHAR_FILTERS

filters that accept character ranges

DEFAULT_BANNER_TYPES
DEFAULT_BRACKET_CHARACTERS_CLOSE
DEFAULT_BRACKET_CHARACTERS_OPEN
DEFAULT_CHARSTRIP
DEFAULT_DIR_GLOB
DEFAULT_FILTER_ORDER

standard order to apply the filters

DEFAULT_JUNKWORDS
DEFAULT_MENDSTR
DEFAULT_WHITESPACE
FLAG_FILTERS

filters that only accept a simple boolean on/off

LATE_FILTERS

filters that MUST run after everything else

MAX_FILTER_LOOPS

the maximum number of times we will allow a filter to be applied before giving up and moving on to the next

SETUP_FILTERS

filters that MUST run early

Public Class Methods

mkopt(name, types, default_val) click to toggle source

Creates an option

@param [String] name the name of the option to create @param [Array] types a list of classes that are valid @param [Object] default_val the value to set initially

# File lib/fixnames/option.rb, line 64
def self.mkopt(name, types, default_val)
  types = [types] unless types.is_a?(Array)
  var = "@#{name}"

  define_method "valid_for_#{name}?" do |value|
    value = nil if value == false
    return true if value.nil?
    return true if value == ''
    types.map do |type|
      value.is_a?(type)
    end.reduce(false) do |t,x|
      t || x
    end
  end

  define_method name do |*args|
    unless instance_variable_defined?(var)
      instance_variable_set(var, default_val)
    end
    if args.length == 1
      unless send("valid_for_#{name}?", args[0])
        raise ArgumentError, "bad type for option"
      end
      instance_variable_set(var, args[0])
    end
    instance_variable_get(var)
  end

  define_method "#{name}=" do |value|
    unless send("valid_for_#{name}?", value)
      raise ArgumentError, "bad type for option"
    end
    instance_variable_set(var, value)
  end
end

Public Instance Methods

all_flags=(val) click to toggle source
# File lib/fixnames/option.rb, line 206
def all_flags=(val)
  Fixnames::Option::FLAG_FILTERS.each do |f|
    send(f, val)
  end
end
expunge_common_prefix!() click to toggle source
# File lib/fixnames/option.rb, line 212
def expunge_common_prefix!
  pfx = Dir['*'].abbrev.keys.min_by{ |k| k.length }.chop
  if pfx && pfx.length > 0
    re = "^#{Regexp.escape(pfx)}"
    STDERR.puts "DWIM-WARN: No REGEX was given to -x/--expunge"
    STDERR.puts "DWIM-WARN: Will expunge the common prefix: %r{#{re}}"
    self.expunge = re
  end
end