Method: Transform::Parser::Color.parse
- Defined in:
- lib/source/redshift/transform.rb
.parse(value) ⇒ Object
call-seq:
Parser::Color.parse(str) -> array or false
Parses a css color value from either hex (#f0f0f0) or rgb triplet (rbg(240,240,240)) to an array of rgb values or returns false if the value cannot be parsed
Parser::Color.parse(‘#fff’) # => [255,255,255] Parser::Color.parse(‘f0f0f0’) # => [240,240,240] Parser::Color.parse(‘rbg(240,240,240)) # => [240,240,240]
Parser::Color.parse(‘40px’) # => false Parser::Color.parse(‘left’) # => false
221 222 223 224 225 |
# File 'lib/source/redshift/transform.rb', line 221 def self.parse(value) # :nodoc `value = value.__value__ || String(value)` `if (value.match(/^#[0-9a-f]{3,6}$/i)) return #{Transform::Parser::Color.hex_to_array(value)}` `((value = value.match(/(\\d+),\\s*(\\d+),\\s*(\\d+)/))) ? #{[value[1], value[2], value[3]]} : false` end |