Class: ColorCode::HSL

Inherits:
Object
  • Object
show all
Includes:
HueSaturation
Defined in:
lib/color_code/hsl.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from HueSaturation

#to_rgb, #to_s

Constructor Details

#initialize(code = nil, h: 0, s: 0, l: 0) ⇒ HSL

Returns a new instance of HSL.



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/color_code/hsl.rb', line 7

def initialize(code=nil, h: 0, s: 0, l: 0)
  if code
    hsl = ColorCode::RGB.new(code).to_hsl
    h, s, l = hsl.to_a
  end

  @h = h
  @s = s
  @l = l
  raise if @h > 360 || @s > 100 || @l > 100
rescue
  raise ArgumentError.new('invalid value')
end

Instance Attribute Details

#hObject

Returns the value of attribute h.



5
6
7
# File 'lib/color_code/hsl.rb', line 5

def h
  @h
end

#lObject

Returns the value of attribute l.



5
6
7
# File 'lib/color_code/hsl.rb', line 5

def l
  @l
end

#sObject

Returns the value of attribute s.



5
6
7
# File 'lib/color_code/hsl.rb', line 5

def s
  @s
end

Instance Method Details

#to_aObject



21
22
23
# File 'lib/color_code/hsl.rb', line 21

def to_a
  [@h, @s, @l]
end

#to_hashObject



25
26
27
# File 'lib/color_code/hsl.rb', line 25

def to_hash
  { h: @h, s: @s, l: @l }
end