class RGBUtils::ComplexContrastColorResolver

Attributes

color[R]
dark_color[R]
light_color[R]

Public Class Methods

new(color, options = {}) click to toggle source
# File lib/rgb_utils/resolvers/complex_contrast_color_resolver.rb, line 3
def initialize(color, options = {})
  @color = color
  @light_color = options.fetch(:light_color, Config.light_color)
  @dark_color = options.fetch(:dark_color, Config.dark_color)
end

Public Instance Methods

for() click to toggle source
# File lib/rgb_utils/resolvers/complex_contrast_color_resolver.rb, line 9
def for
  @result ||= begin
    return dark_color if luminance > luminance_cutoff

    light_color
  end
end

Private Instance Methods

luminance() click to toggle source
# File lib/rgb_utils/resolvers/complex_contrast_color_resolver.rb, line 21
def luminance
  @luminance ||= RelativeLuminanceCalculator.calculate(color)
end
luminance_cutoff() click to toggle source
# File lib/rgb_utils/resolvers/complex_contrast_color_resolver.rb, line 25
def luminance_cutoff
  Math::sqrt(1.05 * 0.05) - 0.05
end