class Colors::HSLA
Public Class Methods
Source
# File lib/colors/hsla.rb, line 3 def initialize(h, s, l, a) @h, @s, @l, @a = canonicalize(h, s, l, a) end
Public Instance Methods
Source
# 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
Calls superclass method
Colors::HSL#==
Source
# File lib/colors/hsla.rb, line 9 def components [h, s, l, a] end
Also aliased as: hsla_components
Source
# File lib/colors/hsla.rb, line 26 def desaturate(factor) HSLA.new(h, s*factor, l, a) end
Source
# 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
Calls superclass method
Colors::HSL#to_hsl
Source
# 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
Calls superclass method
Colors::HSL#to_rgb
Private Instance Methods
Source
# File lib/colors/hsla.rb, line 56 def canonicalize(h, s, l, a) if [s, l, a].map(&:class) == [Integer, Integer, Integer] canonicalize_from_integer(h, s, l, a) else [ Rational(h) % 360, canonicalize_component_to_rational(s, :s), canonicalize_component_to_rational(l, :l), canonicalize_component_to_rational(a, :a) ] end end
Source
# File lib/colors/hsla.rb, line 69 def canonicalize_from_integer(h, s, l, a) check_type(s, Integer, :s) check_type(l, Integer, :l) check_type(a, Integer, :a) [ Rational(h) % 360, canonicalize_component_from_integer(s, :s), canonicalize_component_from_integer(l, :l), canonicalize_component_from_integer(a, :a) ] end