Method: String#validate_color
- Defined in:
- lib/doing/colors.rb
#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.
108 109 110 111 112 113 114 115 116 117 |
# File 'lib/doing/colors.rb', line 108 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) || compiled =~ /^([fb]g?)?#([a-f0-9]{6})$/i end valid_color end |