Class: Stylish::Color::ColorStringParser
- Inherits:
-
Object
- Object
- Stylish::Color::ColorStringParser
- Defined in:
- lib/stylish/color.rb
Overview
A small parser for string color values.
Instance Attribute Summary collapse
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#parse(value) ⇒ Object
Parse a string input, returning an array of numbers corresponding to red, green, blue, and the opacity value.
Instance Attribute Details
#type ⇒ Object (readonly)
Returns the value of attribute type.
437 438 439 |
# File 'lib/stylish/color.rb', line 437 def type @type end |
Instance Method Details
#parse(value) ⇒ Object
Parse a string input, returning an array of numbers corresponding to red, green, blue, and the opacity value.
441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 |
# File 'lib/stylish/color.rb', line 441 def parse(value) value = value.to_s.downcase key = value.to_sym return [:inherit, nil, nil, nil, nil] if value == "inherit" return [:keyword].concat(KEYWORDS[key]) if KEYWORDS.has_key?(key) if value =~ HEX_COLOR return [:hex].concat(self.class.convert_hex(value)) end if value =~ RGB_COLOR return [:rgb].concat(self.class.convert_rgb(value)) end if value =~ RGBA_COLOR return [:rgba].concat(self.class.convert_rgba(value)) end if value =~ HSL_COLOR return [:hsl].concat(self.class.convert_hsl(value)) end if value =~ HSLA_COLOR return [:hsla].concat(self.class.convert_hsla(value)) end nil end |