Class: ColorCode::HSL
- Inherits:
-
Object
- Object
- ColorCode::HSL
- Includes:
- HueSaturation
- Defined in:
- lib/color_code/hsl.rb
Instance Attribute Summary collapse
-
#h ⇒ Object
Returns the value of attribute h.
-
#l ⇒ Object
Returns the value of attribute l.
-
#s ⇒ Object
Returns the value of attribute s.
Instance Method Summary collapse
-
#initialize(code = nil, h: 0, s: 0, l: 0) ⇒ HSL
constructor
A new instance of HSL.
- #to_a ⇒ Object
- #to_hash ⇒ Object
Methods included from HueSaturation
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
#h ⇒ Object
Returns the value of attribute h.
5 6 7 |
# File 'lib/color_code/hsl.rb', line 5 def h @h end |
#l ⇒ Object
Returns the value of attribute l.
5 6 7 |
# File 'lib/color_code/hsl.rb', line 5 def l @l end |
#s ⇒ Object
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_a ⇒ Object
21 22 23 |
# File 'lib/color_code/hsl.rb', line 21 def to_a [@h, @s, @l] end |
#to_hash ⇒ Object
25 26 27 |
# File 'lib/color_code/hsl.rb', line 25 def to_hash { h: @h, s: @s, l: @l } end |