Class: TNS::Palette

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/tns/palette.rb

Overview

Represents a palette based on a color

Instance Method Summary collapse

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

#eachObject



37
38
39
# File 'lib/tns/palette.rb', line 37

def each(&)
  palette.each(&)
end

#shadesObject



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

#tintsObject



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