Class: TNS::Palette
Overview
Represents a palette based on a color
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(color) ⇒ Palette
constructor
A new instance of Palette.
- #shades ⇒ Object
- #tints ⇒ Object
- #to(format) ⇒ Object
Constructor Details
#initialize(color) ⇒ Palette
Returns a new instance of Palette.
8 9 10 |
# File 'lib/tns/palette.rb', line 8 def initialize(color) @color = color end |
Instance Method Details
#each ⇒ Object
37 38 39 |
# File 'lib/tns/palette.rb', line 37 def each(&) palette.each(&) end |
#shades ⇒ Object
18 19 20 21 22 |
# File 'lib/tns/palette.rb', line 18 def shades (1..4).each_with_object([]) do |index, object| object << @color.shade(index) end end |
#tints ⇒ Object
12 13 14 15 16 |
# File 'lib/tns/palette.rb', line 12 def tints (1..4).each_with_object([]) do |index, object| object << @color.tint(index) end.reverse end |
#to(format) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/tns/palette.rb', line 24 def to(format) case format when "hex" map(&:to_hex) when "hsl" map(&:to_hsl) when "rgb" palette else raise ArgumentError, "Invalid color format #{format}. Specify hex, hsl or rgb." end end |