Sha256: e3aeb68edb8dafba99f054b1b79102df1ef6fc71d28b6bb744fee5ed0615fdd3

Contents?: true

Size: 959 Bytes

Versions: 18

Compression:

Stored size: 959 Bytes

Contents

module Mutant
  # Class to colorize strings
  class Color
    include Adamantium::Flat

    # Initialize color object
    #
    # @param [Fixnum] code
    #
    # @return [undefined]
    #
    # @api private
    #
    def initialize(code)
      @code = code
    end

    # Format text with color
    #
    # @param [String] text
    #
    # @return [String]
    #
    # @api private
    #
    def format(text)
      "\e[#{@code}m#{text}\e[0m"
    end

    NONE = Class.new(self) do
      # Format null color
      #
      # @param [String] text
      #
      # @return [String]
      #   returns the argument string
      #
      # @api private
      #
      def format(text)
        text
      end

    private

      # Initialize null color
      #
      # @return [undefined]
      #
      # @api private
      #
      def initialize(*)
      end

    end.new.freeze

    RED   = Color.new(31)
    GREEN = Color.new(32)
    BLUE  = Color.new(34)
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
mutant-0.2.20 lib/mutant/color.rb
mutant-0.2.17 lib/mutant/color.rb
mutant-0.2.16 lib/mutant/color.rb
mutant-0.2.15 lib/mutant/color.rb
mutant-0.2.14 lib/mutant/color.rb
mutant-0.2.13 lib/mutant/color.rb
mutant-0.2.12 lib/mutant/color.rb
mutant-0.2.11 lib/mutant/color.rb
mutant-0.2.9 lib/mutant/color.rb
mutant-0.2.8 lib/mutant/color.rb
mutant-0.2.7 lib/mutant/color.rb
mutant-0.2.6 lib/mutant/color.rb
mutant-0.2.5 lib/mutant/color.rb
mutant-0.2.4 lib/mutant/color.rb
mutant-0.2.3 lib/mutant/color.rb
mutant-0.2.2 lib/mutant/color.rb
mutant-0.2.1 lib/mutant/color.rb
mutant-0.2.0 lib/mutant/color.rb