Class: Chroma::PaletteBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/chroma/palette_builder.rb

Overview

Class internally used to build custom palettes from define_palette.

Defined Under Namespace

Classes: PaletteBuilderDsl

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, &block) ⇒ PaletteBuilder


16
17
18
19
# File 'lib/chroma/palette_builder.rb', line 16

def initialize(name, &block)
  @name = name
  @block = block
end

Class Method Details

.build(name, &block) ⇒ Symbol, String

Wrapper to instantiate a new instance of Chroma::PaletteBuilder and call its #build method.


10
11
12
# File 'lib/chroma/palette_builder.rb', line 10

def self.build(name, &block)
  new(name, &block).build
end

Instance Method Details

#buildSymbol, String

Build the custom palette by defining a new method on Harmonies.


23
24
25
26
27
28
29
30
31
32
33
# File 'lib/chroma/palette_builder.rb', line 23

def build
  dsl = PaletteBuilderDsl.new
  dsl.instance_eval(&@block)
  conversions = dsl.conversions

  Harmonies.send(:define_method, @name) do
    conversions.map do |color_calls|
      color_calls.evaluate(@color)
    end.unshift(@color)
  end
end