class ColorValidator
Checks if the value of an attribute is a valid hex color.
@example Validate that the product color is a valid hex color.
class Product << ActiveRecord::Base attr_accessor :color validates :color, color: true end
Constants
- HEX_COLOR_FORMAT
Private Instance Methods
valid?(color, _)
click to toggle source
# File lib/missing_validators/validators/color_validator.rb, line 13 def valid?(color, _) (color =~ HEX_COLOR_FORMAT).present? end