Class: ColorConversion::NameConverter

Inherits:
ColorConverter show all
Defined in:
lib/color_conversion/converters/name_converter.rb

Instance Attribute Summary

Attributes inherited from ColorConverter

#rgba

Class Method Summary collapse

Methods inherited from ColorConverter

#alpha, #cmyk, factory, #hex, #hsb, #hsl, #hsv, inherited, #initialize, #name, #rgb

Constructor Details

This class inherits a constructor from ColorConversion::ColorConverter

Class Method Details

.matches?(color) ⇒ Boolean

Returns:

  • (Boolean)


4
5
6
7
8
# File 'lib/color_conversion/converters/name_converter.rb', line 4

def self.matches?(color)
  return false unless color.kind_of?(String)

  color_names.include?(color.downcase.to_sym)
end

.name_for_rgb(rgb) ⇒ Object



10
11
12
13
# File 'lib/color_conversion/converters/name_converter.rb', line 10

def self.name_for_rgb(rgb)
  name = color_names.find {|k,v| v == [rgb[:r], rgb[:g], rgb[:b]] }
  name[0].to_s if name
end