Sha256: 8d953bbf6a419dd610fe80ad95e376f1e8e6e5a3523ad161ae63d3e0967670d0

Contents?: true

Size: 1.01 KB

Versions: 6

Compression:

Stored size: 1.01 KB

Contents

# encoding: utf-8

module Pastel
  # A class responsible for importing color aliases
  class AliasImporter
    # Create alias importer
    #
    # @example
    #   importer = Pastel::AliasImporter.new(Pastel::Color.new)
    #
    # @api public
    def initialize(color, output = $stderr)
      @color  = color
      @output = output
    end

    # Import aliases from the environment
    #
    # @example
    #   importer = Pastel::AliasImporter.new(Pastel::Color.new)
    #   importer.import
    #
    # @return [nil]
    #
    # @api public
    def import
      color_aliases = ENV['PASTEL_COLORS_ALIASES']
      return unless color_aliases
      color_aliases.split(',').each do |color_alias|
        new_color, old_color = color_alias.split('=').map(&:to_sym)
        if !new_color || !old_color
          output.puts "Bad color mapping `#{color_alias}`"
        else
          color.alias_color(new_color, old_color)
        end
      end
    end

    protected

    attr_reader :color, :output
  end # AliasImporter
end # Pastel

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
pastel-0.5.3 lib/pastel/alias_importer.rb
pastel-0.5.2 lib/pastel/alias_importer.rb
pastel-0.5.1 lib/pastel/alias_importer.rb
pastel-0.5.0 lib/pastel/alias_importer.rb
pastel-0.4.0 lib/pastel/alias_importer.rb
pastel-0.3.0 lib/pastel/alias_importer.rb