Class: String
- Defined in:
- lib/doing/colors.rb,
lib/doing/good.rb,
lib/doing/normalize.rb
Overview
String to symbol conversion
Direct Known Subclasses
Instance Method Summary collapse
-
#good? ⇒ Boolean
Tests if object is nil or empty.
-
#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_color ⇒ String
Normalize a color name, removing underscores, replacing "bright" with "bold", and converting bgbold to boldbg.
-
#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
-
#validate_color ⇒ String
Extract the longest valid %color name from a string.
Instance Method Details
#good? ⇒ Boolean
Tests if object is nil or empty
24 25 26 |
# File 'lib/doing/good.rb', line 24 def good? !strip.empty? end |
#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_color ⇒ String
Normalize a color name, removing underscores, replacing "bright" with "bold", and converting bgbold to boldbg
116 117 118 |
# File 'lib/doing/colors.rb', line 116 def normalize_color gsub(/_/, '').sub(/bright/i, 'bold').sub(/bgbold/, 'boldbg') 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 |
#validate_color ⇒ String
Extract the longest valid %color name from a string.
Allows %colors to bleed into other text and still be recognized, e.g. %greensomething still finds %green.
98 99 100 101 102 103 104 105 106 107 |
# File 'lib/doing/colors.rb', line 98 def validate_color valid_color = nil compiled = '' normalize_color.split('').each do |char| compiled += char valid_color = compiled if Color.attributes.include?(compiled.to_sym) end valid_color end |