Class: Colors::HSLA

Inherits:
HSL show all
Includes:
AlphaComponent
Defined in:
lib/colors/hsla.rb

Instance Attribute Summary

Attributes included from AlphaComponent

#a

Attributes inherited from HSL

#h, #l, #s

Instance Method Summary collapse

Methods inherited from HSL

#rgb_components

Methods inherited from AbstractColor

#inspect

Constructor Details

#initialize(h, s, l, a) ⇒ HSLA

Returns a new instance of HSLA.



3
4
5
# File 'lib/colors/hsla.rb', line 3

def initialize(h, s, l, a)
  @h, @s, @l, @a = canonicalize(h, s, l, a)
end

Instance Method Details

#==(other) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/colors/hsla.rb', line 15

def ==(other)
  case other
  when HSLA
    h == other.h && s == other.s && l == other.l && a == other.a
  when HSL
    h == other.h && s == other.s && l == other.l && a == 1r
  else
    super
  end
end

#componentsObject Also known as: hsla_components



9
10
11
# File 'lib/colors/hsla.rb', line 9

def components
  [h, s, l, a]
end

#desaturate(factor) ⇒ Object



26
27
28
# File 'lib/colors/hsla.rb', line 26

def desaturate(factor)
  HSLA.new(h, s*factor, l, a)
end

#to_hslObject



38
39
40
41
42
43
44
45
# File 'lib/colors/hsla.rb', line 38

def to_hsl
  if a == 1r
    super
  else
    raise NotImplementedError,
          "Unable to convert non-opaque HSLA to HSL"
  end
end

#to_hslaObject



30
31
32
# File 'lib/colors/hsla.rb', line 30

def to_hsla
  self
end

#to_rgbObject



47
48
49
50
51
52
53
54
# File 'lib/colors/hsla.rb', line 47

def to_rgb
  if a == 1r
    super
  else
    raise NotImplementedError,
          "Unable to convert non-opaque HSLA to RGB"
  end
end

#to_rgbaObject



34
35
36
# File 'lib/colors/hsla.rb', line 34

def to_rgba
  RGBA.new(*rgb_components, a)
end