Skip to content

Instantly share code, notes, and snippets.

@lee-dohm
Last active December 18, 2015 03:59
Show Gist options
  • Save lee-dohm/5722529 to your computer and use it in GitHub Desktop.
Save lee-dohm/5722529 to your computer and use it in GitHub Desktop.
Code samples for blog article: "The Importance of Documenting Code"
# Indicates whether `color` is a valid SVG color string.
#
# [SVG color descriptions](http://www.w3.org/TR/SVG/types.html#DataTypeColor) are one of the following:
#
# * RGB values
# * `#rgb`
# * `#rrggbb`
# * `rgb(255, 0, 0)` - *not currently supported by KangaRuby*
# * `rgb(100%, 0%, 0%)` - *not currently supported by KangaRuby*
# * [Color names](http://www.w3.org/TR/SVG/types.html#ColorKeywords)
#
# @param [String] color Color value to validate.
# @return [Boolean] Flag indicating if `color` is a valid SVG color value.
# @see KangaRuby::COLOR_NAMES
# @todo Add support for decimal and float RGB values.
def valid_color?(color)
return color =~ /^#[0-9A-Fa-f]{3}([0-9A-Fa-f]{3})?$/ if color[0] == '#'
COLOR_NAMES.include?(color)
end
def valid_color?(color)
return color =~ /^#[0-9A-Fa-f]{3}([0-9A-Fa-f]{3})?$/ if color[0] == '#'
COLOR_NAMES.include?(color)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment