Method: ColorFun::HSL#name

Defined in:
lib/color_fun/hsl.rb

#nameObject

Return a name for this colour



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/color_fun/hsl.rb', line 11

def name
  Array.new.tap do |s|
    if @saturation == 0 && @lightness == 0
      s << "Black"
    elsif @saturation == 0 && @lightness == 100
      s << "White"
    elsif @saturation <= 15 && @saturation > 0
      s << "Light"
    elsif @lightness < 40 && @saturation > 0
      s << "Dark"
    end
    
    if @saturation > 0
      s << case @hue
      when 0..8, 347..360 then 'Red'
      when 9..42          then 'Orange'
      when 43..61         then 'Yellow'
      when 62..158        then 'Green'
      when 159..264       then 'Blue'
      when 265..285       then 'Purple'
      when 286..346       then 'Pink'
      end
    else
      s << "Grey"
    end
  end.join(' ')
end