Sha256: cc3d565a4bc879fafe44dfc8ee9846aa698092f897a7538bdef2b4079e07af19

Contents?: true

Size: 470 Bytes

Versions: 1

Compression:

Stored size: 470 Bytes

Contents

# Allows to check if the value of a specific 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
class ColorValidator < BaseValidator
  def self.validate_format(color)
    !!(color =~ /^#(?:[0-9a-f]{3})(?:[0-9a-f]{3})?$/i)
  end

  private

  def self.valid?(color, options)
    validate_format(color)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
missing_validators-1.1.0 lib/missing_validators/validators/color_validator.rb