Class: CSSColor
- Inherits:
-
Object
- Object
- CSSColor
- Defined in:
- lib/css_color.rb
Defined Under Namespace
Classes: UnknownColorError
Class Method Summary collapse
Class Method Details
.parse(string) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/css_color.rb', line 6 def self.parse(string) case string when /#/ Color::RGB.from_html(string) when /%/ integers = extract(string, max = 100) Color::RGB.from_percentage(*integers) when /rgb/i integers = extract(string, max = 255) Color::RGB.new(*integers) else Color::CSS[string] end or raise ArgumentError rescue ArgumentError raise UnknownColorError.new( "Couldn't make sense of #{string.inspect}" ) end |