Class: Sai::Mei::Palette Abstract Private
- Inherits:
-
Object
- Object
- Sai::Mei::Palette
- Defined in:
- lib/sai/mei/palette.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Include in subclass and define a constant named COLORS
The base module for color palettes
Instance Attribute Summary collapse
-
#candidates ⇒ Hash{Symbol => Array<Integer>}
readonly
The candidates to be installed.
Class Method Summary collapse
-
.load(config_name) ⇒ Palette
private
Load the Palette from configuration.
Instance Method Summary collapse
-
#color_names ⇒ Array<Symbol>
Get all the names of the color names available in the Palette.
-
#excluding(*color_names) ⇒ Palette
Exclude colors from the palette.
-
#initialize(lookup) ⇒ Palette
constructor
private
Initialize a new instance of the Palette.
-
#install ⇒ void
Install the candidates into Sai.
-
#only(*color_names) ⇒ self
Limit the color palette to specific named colors.
-
#rename(**color_map) ⇒ self
Change the name specific colors in the palette.
-
#reset! ⇒ Palette
Reset the candidates to the original state.
Constructor Details
#initialize(lookup) ⇒ Palette
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initialize a new instance of the Palette
60 61 62 63 |
# File 'lib/sai/mei/palette.rb', line 60 def initialize(lookup) @candidates = lookup.dup @lookup = lookup.freeze end |
Instance Attribute Details
#candidates ⇒ Hash{Symbol => Array<Integer>} (readonly)
The candidates to be installed
23 24 25 |
# File 'lib/sai/mei/palette.rb', line 23 def candidates @candidates end |
Class Method Details
.load(config_name) ⇒ Palette
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Load the Palette from configuration
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/sai/mei/palette.rb', line 36 def self.load(config_name) lookup = YAML.load_file( File.("../../../config/#{config_name.to_s.downcase}.yml", File.dirname(__FILE__)), symbolize_names: true ) if Sai::Mei.const_defined?(config_name) Sai::Mei.const_get(config_name).new(lookup) else Sai::Mei.const_set(config_name, Class.new(Palette)).new(lookup) end end |
Instance Method Details
#color_names ⇒ Array<Symbol>
Get all the names of the color names available in the Palette
76 77 78 |
# File 'lib/sai/mei/palette.rb', line 76 def color_names @lookup.keys end |
#excluding(*color_names) ⇒ Palette
Exclude colors from the palette
94 95 96 97 |
# File 'lib/sai/mei/palette.rb', line 94 def excluding(*color_names) @candidates = candidates.except(*color_names.map(&:to_sym)) self end |
#install ⇒ void
This method returns an undefined value.
Install the candidates into Sai
111 112 113 |
# File 'lib/sai/mei/palette.rb', line 111 def install candidates.each_pair { |name, color| Sai.register(name, color) } end |
#only(*color_names) ⇒ self
Limit the color palette to specific named colors
129 130 131 132 |
# File 'lib/sai/mei/palette.rb', line 129 def only(*color_names) @candidates = candidates.slice(*color_names.map(&:to_sym)) self end |
#rename(**color_map) ⇒ self
Change the name specific colors in the palette
148 149 150 151 152 153 154 155 156 157 |
# File 'lib/sai/mei/palette.rb', line 148 def rename(**color_map) color_map = color_map.transform_keys(&:to_sym).transform_values(&:to_sym) #: Hash[Symbol, Symbol] color_map.each_pair do |old_name, new_name| next unless candidates.key?(old_name) candidates[new_name] = candidates.delete(old_name) # steep:ignore ArgumentTypeMismatch end self end |
#reset! ⇒ Palette
Reset the candidates to the original state
173 174 175 |
# File 'lib/sai/mei/palette.rb', line 173 def reset! self.class.new(@lookup.dup) end |