Class: Pastel::AliasImporter

Inherits:
Object
  • Object
show all
Defined in:
lib/pastel/alias_importer.rb

Overview

A class responsible for importing color aliases

Instance Method Summary collapse

Constructor Details

#initialize(color, env, output = $stderr) ⇒ AliasImporter

Create alias importer

Examples:

importer = Pastel::AliasImporter.new(Pastel::Color.new, {})


12
13
14
15
16
# File 'lib/pastel/alias_importer.rb', line 12

def initialize(color, env, output = $stderr)
  @color  = color
  @env    = env
  @output = output
end

Instance Method Details

#importnil

Import aliases from the environment

Examples:

importer = Pastel::AliasImporter.new(Pastel::Color.new, {})
importer.import

Returns:

  • (nil)


27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/pastel/alias_importer.rb', line 27

def import
  color_aliases = env["PASTEL_COLORS_ALIASES"]
  return unless color_aliases

  color_aliases.split(",").each do |color_alias|
    new_color, old_colors = color_alias.split("=")
    if !new_color || !old_colors
      output.puts "Bad color mapping `#{color_alias}`"
    else
      color.alias_color(new_color.to_sym,
                        *old_colors.split(".").map(&:to_sym))
    end
  end
end