Module: Doing::StringNormalize
- Included in:
- String
- Defined in:
- lib/doing/normalize.rb
Overview
String to symbol conversion
Instance Method Summary collapse
-
#normalize_age(default = :newest) ⇒ Symbol
Convert an age string to a qualified type.
- #normalize_age!(default = :newest) ⇒ Object
-
#normalize_bool(default = :and) ⇒ Object
Convert a boolean string to a symbol.
- #normalize_bool!(default = :and) ⇒ Object
-
#normalize_case(default = :smart) ⇒ Object
Convert a case sensitivity string to a symbol.
- #normalize_case!(default = :smart) ⇒ Object
- #normalize_change_type ⇒ Object
-
#normalize_matching(default = :pattern) ⇒ Object
Convert a matching configuration string to a symbol.
- #normalize_matching!(default = :pattern) ⇒ Object
- #normalize_order(default = :asc) ⇒ Object
-
#normalize_order!(default = :asc) ⇒ Symbol
Convert a sort order string to a qualified type.
-
#normalize_tag_sort(default = :name) ⇒ Symbol
Convert tag sort string to a qualified type.
- #normalize_tag_sort!(default = :name) ⇒ Object
-
#normalize_trigger ⇒ String
Adds ?: to any parentheticals in a regular expression to avoid match groups.
- #normalize_trigger! ⇒ Object
Instance Method Details
#normalize_age(default = :newest) ⇒ Symbol
Convert an age string to a qualified type
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/doing/normalize.rb', line 34 def normalize_age(default = :newest) case self when /^o/i :oldest when /^n/i :newest else default end end |
#normalize_age!(default = :newest) ⇒ Object
46 47 48 |
# File 'lib/doing/normalize.rb', line 46 def normalize_age!(default = :newest) replace normalize_age(default) end |
#normalize_bool(default = :and) ⇒ Object
Convert a boolean string to a symbol
98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/doing/normalize.rb', line 98 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
114 115 116 |
# File 'lib/doing/normalize.rb', line 114 def normalize_bool!(default = :and) replace normalize_bool(default) end |
#normalize_case(default = :smart) ⇒ Object
Convert a case sensitivity string to a symbol
75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/doing/normalize.rb', line 75 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
89 90 91 |
# File 'lib/doing/normalize.rb', line 89 def normalize_case!(default = :smart) replace normalize_case(default) end |
#normalize_change_type ⇒ Object
159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/doing/normalize.rb', line 159 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_matching(default = :pattern) ⇒ Object
Convert a matching configuration string to a symbol
126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/doing/normalize.rb', line 126 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
140 141 142 |
# File 'lib/doing/normalize.rb', line 140 def normalize_matching!(default = :pattern) replace normalize_bool(default) end |
#normalize_order(default = :asc) ⇒ Object
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/doing/normalize.rb', line 59 def normalize_order(default = :asc) case self when /^a/i :asc when /^d/i :desc else default end end |
#normalize_order!(default = :asc) ⇒ Symbol
Convert a sort order string to a qualified type
55 56 57 |
# File 'lib/doing/normalize.rb', line 55 def normalize_order!(default = :asc) replace normalize_order(default) end |
#normalize_tag_sort(default = :name) ⇒ Symbol
Convert tag sort string to a qualified type
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 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_trigger ⇒ String
Adds ?: to any parentheticals in a regular expression to avoid match groups
150 151 152 |
# File 'lib/doing/normalize.rb', line 150 def normalize_trigger gsub(/\((?!\?:)/, '(?:').downcase end |
#normalize_trigger! ⇒ Object
155 156 157 |
# File 'lib/doing/normalize.rb', line 155 def normalize_trigger! replace normalize_trigger end |