class Sass::Script::Color
A SassScript object representing a CSS color.
def div(other)
-
(Sass::SyntaxError)
- if `other` is a number with units
Returns:
-
(Color)
- The resulting color
Parameters:
-
other
(Literal
) -- The right-hand side of the operator
def div(other) if other.is_a?(Sass::Script::Number) || other.is_a?(Sass::Script::Color) piecewise(other, :/) else super end end
def initialize(rgb)
-
(Sass::SyntaxError)
- if any color value isn't between 0 and 255
Parameters:
-
rgb
(Array
) -- A three-element array of the red, green, and blue values (respectively)
def initialize(rgb) rgb = rgb.map {|c| c.to_i} raise Sass::SyntaxError.new("Color values must be between 0 and 255") if rgb.any? {|c| c < 0 || c > 255} super(rgb.freeze) end
def minus(other)
-
(Sass::SyntaxError)
- if `other` is a number with units
Returns:
-
(Color)
- The resulting color
Parameters:
-
other
(Literal
) -- The right-hand side of the operator
def minus(other) if other.is_a?(Sass::Script::Number) || other.is_a?(Sass::Script::Color) piecewise(other, :-) else super end end
def mod(other)
-
(Sass::SyntaxError)
- if `other` is a number with units
Returns:
-
(Color)
- The resulting color
Parameters:
-
other
(Number, Color
) -- The right-hand side of the operator
def mod(other) if other.is_a?(Sass::Script::Number) || other.is_a?(Sass::Script::Color) piecewise(other, :%) else raise NoMethodError.new(nil, :mod) end end
def piecewise(other, operation)
def piecewise(other, operation) other_num = other.is_a? Number if other_num && !other.unitless? raise Sass::SyntaxError.new("Cannot add a number with units (#{other}) to a color (#{self}).") end result = [] for i in (0...3) res = rgb[i].send(operation, other_num ? other.value : other.rgb[i]) result[i] = [ [res, 255].min, 0 ].max end with(:red => result[0], :green => result[1], :blue => result[2]) end
def plus(other)
-
(Sass::SyntaxError)
- if `other` is a number with units
Returns:
-
(Color)
- The resulting color
Parameters:
-
other
(Literal
) -- The right-hand side of the operator
def plus(other) if other.is_a?(Sass::Script::Number) || other.is_a?(Sass::Script::Color) piecewise(other, :+) else super end end
def rgb
-
(Array
- A frozen three-element array of the red, green, and blue)
def rgb @value end
def times(other)
-
(Sass::SyntaxError)
- if `other` is a number with units
Returns:
-
(Color)
- The resulting color
Parameters:
-
other
(Number, Color
) -- The right-hand side of the operator
def times(other) if other.is_a?(Sass::Script::Number) || other.is_a?(Sass::Script::Color) piecewise(other, :*) else raise NoMethodError.new(nil, :times) end end
def to_s
-
(String)
- The string representation
def to_s return HTML4_COLORS_REVERSE[rgb] if HTML4_COLORS_REVERSE[rgb] red, green, blue = rgb.map { |num| num.to_s(16).rjust(2, '0') } "##{red}#{green}#{blue}" end
def value
- See: #rgb -
Deprecated:
- This will be removed in version 2.6.
def value warn <<END ECATION WARNING: Sass::Script::Color #value attribute is deprecated and will be ved in version 2.6. Use the #rgb attribute instead. rgb end
def with(attrs)
-
(Color)
- The new Color object
Parameters:
-
attrs
(Hash
) --
def with(attrs) Color.new([ attrs[:red] || rgb[0], attrs[:green] || rgb[1], attrs[:blue] || rgb[2], ]) end