Class: RGBUtils::SimpleContrastColorResolver

Inherits:
Resolver
  • Object
show all
Defined in:
lib/rgb_utils/resolvers/simple_contrast_color_resolver.rb

Constant Summary collapse

THRESHOLD_VALUE =
186/255.0

Instance Method Summary collapse

Methods inherited from Resolver

for

Constructor Details

#initialize(color, options = {}) ⇒ SimpleContrastColorResolver

Returns a new instance of SimpleContrastColorResolver.



5
6
7
8
9
# File 'lib/rgb_utils/resolvers/simple_contrast_color_resolver.rb', line 5

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

Instance Method Details

#forObject



11
12
13
14
15
16
17
# File 'lib/rgb_utils/resolvers/simple_contrast_color_resolver.rb', line 11

def for
  @result ||= begin
    return dark_color if luma > THRESHOLD_VALUE

    light_color
  end
end