class Colors::HSLA
Public Class Methods
new(h, s, l, a)
click to toggle 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
==(other)
click to toggle source
Calls superclass method
Colors::HSL#==
# 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
components()
click to toggle source
# File lib/colors/hsla.rb, line 9 def components [h, s, l, a] end
Also aliased as: hsla_components
desaturate(factor)
click to toggle source
# File lib/colors/hsla.rb, line 26 def desaturate(factor) HSLA.new(h, s*factor, l, a) end
to_hsl()
click to toggle source
Calls superclass method
Colors::HSL#to_hsl
# 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_hsla()
click to toggle source
# File lib/colors/hsla.rb, line 30 def to_hsla self end
to_rgb()
click to toggle source
Calls superclass method
Colors::HSL#to_rgb
# 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_rgba()
click to toggle source
# File lib/colors/hsla.rb, line 34 def to_rgba RGBA.new(*rgb_components, a) end
Private Instance Methods
canonicalize(h, s, l, a)
click to toggle 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
canonicalize_from_integer(h, s, l, a)
click to toggle 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