Method: String#validate_color

Defined in:
lib/howzit/colors.rb

#validate_colorString

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.



111
112
113
114
115
116
117
118
119
120
# File 'lib/howzit/colors.rb', line 111

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