Module: Doing::StringNormalize

Included in:
String
Defined in:
lib/doing/normalize.rb

Overview

String to symbol conversion

Instance Method Summary collapse

Instance Method Details

#normalize_age(default = :newest) ⇒ Symbol

Convert an age string to a qualified type

Returns:

  • (Symbol)

    :oldest or :newest



54
55
56
57
58
59
60
61
62
63
# 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) ⇒ Object

See Also:



66
67
68
# File 'lib/doing/normalize.rb', line 66

def normalize_age!(default = :newest)
  replace normalize_age(default)
end

#normalize_bool(default = :and) ⇒ Object

Convert a boolean string to a symbol

Returns:

  • Symbol :and, :or, or :not



118
119
120
121
122
123
124
125
126
127
128
129
130
131
# 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) ⇒ Object

See Also:



134
135
136
# File 'lib/doing/normalize.rb', line 134

def normalize_bool!(default = :and)
  replace normalize_bool(default)
end

#normalize_case(default = :smart) ⇒ Object

Convert a case sensitivity string to a symbol

Returns:

  • Symbol :smart, :sensitive, :ignore



95
96
97
98
99
100
101
102
103
104
105
106
# 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) ⇒ Object

See Also:



109
110
111
# File 'lib/doing/normalize.rb', line 109

def normalize_case!(default = :smart)
  replace normalize_case(default)
end

#normalize_change_typeObject



179
180
181
182
183
184
185
186
187
188
189
190
# 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) ⇒ Symbol

Normalize list output style

Parameters:

  • default (defaults to: :space)

    The default

Returns:

  • (Symbol)

    :comma, :column, :tab, :space



36
37
38
39
40
41
42
43
44
45
46
47
# 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) ⇒ Object

Convert a matching configuration string to a symbol

Parameters:

  • default (Symbol) (defaults to: :pattern)

    the default matching type to return if the string doesn't match a known symbol

Returns:

  • Symbol :fuzzy, :pattern, :exact



146
147
148
149
150
151
152
153
154
155
156
157
# 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) ⇒ Object



160
161
162
# File 'lib/doing/normalize.rb', line 160

def normalize_matching!(default = :pattern)
  replace normalize_bool(default)
end

#normalize_order(default = :asc) ⇒ Object



79
80
81
82
83
84
85
86
87
88
# 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) ⇒ Symbol

Convert a sort order string to a qualified type

Returns:



75
76
77
# File 'lib/doing/normalize.rb', line 75

def normalize_order!(default = :asc)
  replace normalize_order(default)
end

#normalize_tag_sort(default = :name) ⇒ Symbol

Convert tag sort string to a qualified type

Returns:



13
14
15
16
17
18
19
20
21
22
# 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) ⇒ Object



25
26
27
# File 'lib/doing/normalize.rb', line 25

def normalize_tag_sort!(default = :name)
  replace normalize_tag_sort(default)
end

#normalize_triggerString

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

Returns:

  • (String)

    modified regular expression



170
171
172
# File 'lib/doing/normalize.rb', line 170

def normalize_trigger
  gsub(/\((?!\?:)/, '(?:').downcase
end

#normalize_trigger!Object

See Also:



175
176
177
# File 'lib/doing/normalize.rb', line 175

def normalize_trigger!
  replace normalize_trigger
end