Last active
December 18, 2015 03:59
-
-
Save lee-dohm/5722529 to your computer and use it in GitHub Desktop.
Code samples for blog article: "The Importance of Documenting Code"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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