Method: ColorContrastCalc::Color#initialize

Defined in:
lib/color_contrast_calc/color.rb

#initialize(rgb, name = nil) ⇒ Color

Create a new instance of Color.

Parameters:

  • rgb (Array<Integer>, String)

    RGB value represented as an array of integers or hex color code such as [255, 255, 0] or “#ffff00”.

  • name (String) (defaults to: nil)

    You can name the color to be created. Without this option, a color keyword name (if exists) or the value of normalized hex color code is assigned instead.



229
230
231
232
233
234
235
# File 'lib/color_contrast_calc/color.rb', line 229

def initialize(rgb, name = nil)
  @rgb = rgb.is_a?(String) ? Utils.hex_to_rgb(rgb) : rgb.dup
  @opacity = @rgb.length == 4 ? @rgb.pop : 1.0
  @hex = Utils.rgb_to_hex(@rgb)
  @name = name || common_name
  @relative_luminance = Checker.relative_luminance(@rgb)
end