Module: ChromaWcagContrast

Defined in:
lib/chroma_wcag_contrast.rb,
lib/chroma_wcag_contrast/version.rb

Constant Summary collapse

VERSION =
'0.0.1'

Class Method Summary collapse

Class Method Details

.ratio(color1, color2) ⇒ Float

Parameters:

  • color1 (Chroma::Color)
  • color2 (Chroma::Color)

Returns:

  • (Float)


7
8
9
10
11
12
13
14
15
16
# File 'lib/chroma_wcag_contrast.rb', line 7

def ratio(color1, color2)
  high = luminance(color1)
  low = luminance(color2)

  if low > high
    high, low = low, high
  end

  (high + 0.05) / (low + 0.05)
end