Class: RainbowUnicorn::Palette
- Inherits:
-
Object
- Object
- RainbowUnicorn::Palette
- Defined in:
- lib/rainbow_unicorn/palette.rb
Class Method Summary collapse
Instance Method Summary collapse
- #[](code) ⇒ Object
- #colors ⇒ Object (also: #to_a, #to_ary)
- #each ⇒ Object
- #each_color ⇒ Object
- #each_name ⇒ Object
-
#initialize(colors) ⇒ Palette
constructor
A new instance of Palette.
- #names ⇒ Object
- #rgb_colors ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(colors) ⇒ Palette
Returns a new instance of Palette.
9 10 11 12 |
# File 'lib/rainbow_unicorn/palette.rb', line 9 def initialize(colors) @colors = colors.freeze freeze end |
Class Method Details
.define(**colors) ⇒ Object
3 4 5 6 7 |
# File 'lib/rainbow_unicorn/palette.rb', line 3 def self.define(**colors) new( colors.transform_values { |rgb| RainbowUnicorn::Color.new(*rgb) } ) end |
Instance Method Details
#[](code) ⇒ Object
45 46 47 |
# File 'lib/rainbow_unicorn/palette.rb', line 45 def [](code) @colors[code] end |
#colors ⇒ Object Also known as: to_a, to_ary
26 27 28 |
# File 'lib/rainbow_unicorn/palette.rb', line 26 def colors @colors.values end |
#each ⇒ Object
14 15 16 |
# File 'lib/rainbow_unicorn/palette.rb', line 14 def each(&) @colors.each(&) end |
#each_color ⇒ Object
33 34 35 |
# File 'lib/rainbow_unicorn/palette.rb', line 33 def each_color(&) @colors.values.each(&) end |
#each_name ⇒ Object
22 23 24 |
# File 'lib/rainbow_unicorn/palette.rb', line 22 def each_name(&) @colors.keys.each(&) end |
#names ⇒ Object
18 19 20 |
# File 'lib/rainbow_unicorn/palette.rb', line 18 def names @colors.keys end |
#rgb_colors ⇒ Object
37 38 39 |
# File 'lib/rainbow_unicorn/palette.rb', line 37 def rgb_colors @colors.values.map(&:rgb) end |
#to_h ⇒ Object
41 42 43 |
# File 'lib/rainbow_unicorn/palette.rb', line 41 def to_h @colors end |