module Doing::StringNormalize

String to symbol conversion

Public Instance Methods

normalize_age(default = :newest) click to toggle source

Convert an age string to a qualified type

@return [Symbol] :oldest or :newest

# File lib/doing/normalize.rb, line 54
def normalize_age(default = :newest)
  case self
  when /^o/i
    :oldest
  when /^n/i
    :newest
  else
    default.is_a?(Symbol) ? default : default.normalize_age
  end
end
normalize_age!(default = :newest) click to toggle source

@see normalize_age

# File lib/doing/normalize.rb, line 66
def normalize_age!(default = :newest)
  replace normalize_age(default)
end
normalize_bool(default = :and) click to toggle source

Convert a boolean string to a symbol

@return Symbol :and, :or, or :not

# File lib/doing/normalize.rb, line 118
def normalize_bool(default = :and)
  case self
  when /(and|all)/i
    :and
  when /(any|or)/i
    :or
  when /(not|none)/i
    :not
  when /^p/i
    :pattern
  else
    default.is_a?(Symbol) ? default : default.normalize_bool
  end
end
normalize_bool!(default = :and) click to toggle source

@see normalize_bool

# File lib/doing/normalize.rb, line 134
def normalize_bool!(default = :and)
  replace normalize_bool(default)
end
normalize_case(default = :smart) click to toggle source

Convert a case sensitivity string to a symbol

@return Symbol :smart, :sensitive, :ignore

# File lib/doing/normalize.rb, line 95
def normalize_case(default = :smart)
  case self
  when /^(c|sens)/i
    :sensitive
  when /^i/i
    :ignore
  when /^s/i
    :smart
  else
    default.is_a?(Symbol) ? default : default.normalize_case
  end
end
normalize_case!(default = :smart) click to toggle source

@see normalize_case

# File lib/doing/normalize.rb, line 109
def normalize_case!(default = :smart)
  replace normalize_case(default)
end
normalize_change_type() click to toggle source
# File lib/doing/normalize.rb, line 179
def normalize_change_type
  case self
  when /^c/i
    :changed
  when /^i/i
    :improved
  when /^f/i
    :fixed
  when /^n/i
    :new
  end
end
normalize_list_style(default = :space) click to toggle source

Normalize list output style

@param default The default

@return [Symbol] :comma, :column, :tab, :space

# File lib/doing/normalize.rb, line 36
def normalize_list_style(default = :space)
  case self
  when /^c(om|sv)/i
    :comma
  when /^c/i
    :column
  when /^t/i
    :tab
  else
    default.is_a?(Symbol) ? default : default.normalize_list_style
  end
end
normalize_matching(default = :pattern) click to toggle source

Convert a matching configuration string to a symbol

@param default [Symbol] the default matching type to return if the string doesn’t match a known symbol @return Symbol :fuzzy, :pattern, :exact

# File lib/doing/normalize.rb, line 146
def normalize_matching(default = :pattern)
  case self
  when /^f/i
    :fuzzy
  when /^p/i
    :pattern
  when /^e/i
    :exact
  else
    default.is_a?(Symbol) ? default : default.normalize_matching
  end
end
normalize_matching!(default = :pattern) click to toggle source

@see normalize_matching

# File lib/doing/normalize.rb, line 160
def normalize_matching!(default = :pattern)
  replace normalize_bool(default)
end
normalize_order(default = :asc) click to toggle source
# File lib/doing/normalize.rb, line 79
def normalize_order(default = :asc)
  case self
  when /^a/i
    :asc
  when /^d/i
    :desc
  else
    default.is_a?(Symbol) ? default : default.normalize_order
  end
end
normalize_order!(default = :asc) click to toggle source

Convert a sort order string to a qualified type

@return [Symbol] :asc or :desc

# File lib/doing/normalize.rb, line 75
def normalize_order!(default = :asc)
  replace normalize_order(default)
end
normalize_tag_sort(default = :name) click to toggle source

Convert tag sort string to a qualified type

@return [Symbol] :name or :time

# File lib/doing/normalize.rb, line 13
def normalize_tag_sort(default = :name)
  case self
  when /^n/i
    :name
  when /^t/i
    :time
  else
    default.is_a?(Symbol) ? default : default.normalize_tag_sort
  end
end
normalize_tag_sort!(default = :name) click to toggle source

@see normalize_tag_sort

# File lib/doing/normalize.rb, line 25
def normalize_tag_sort!(default = :name)
  replace normalize_tag_sort(default)
end
normalize_trigger() click to toggle source

Adds ?: to any parentheticals in a regular expression to avoid match groups

@return [String] modified regular expression

# File lib/doing/normalize.rb, line 170
def normalize_trigger
  gsub(/\((?!\?:)/, '(?:').downcase
end
normalize_trigger!() click to toggle source

@see normalize_trigger

# File lib/doing/normalize.rb, line 175
def normalize_trigger!
  replace normalize_trigger
end