Sha256: 44b09d2f8214aa244b9de54329b56271cf2c45d5cbe425ea7b0ccbb8f9491e94

Contents?: true

Size: 976 Bytes

Versions: 20

Compression:

Stored size: 976 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 # Color
end # Mutant

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
mutant-0.3.0.beta21 lib/mutant/color.rb
mutant-0.3.0.beta20 lib/mutant/color.rb
mutant-0.3.0.beta19 lib/mutant/color.rb
mutant-0.3.0.beta18 lib/mutant/color.rb
mutant-0.3.0.beta17 lib/mutant/color.rb
mutant-0.3.0.beta16 lib/mutant/color.rb
mutant-0.3.0.beta15 lib/mutant/color.rb
mutant-0.3.0.beta14 lib/mutant/color.rb
mutant-0.3.0.beta13 lib/mutant/color.rb
mutant-0.3.0.beta12 lib/mutant/color.rb
mutant-0.3.0.beta11 lib/mutant/color.rb
mutant-0.3.0.beta10 lib/mutant/color.rb
mutant-0.3.0.beta9 lib/mutant/color.rb
mutant-0.3.0.beta8 lib/mutant/color.rb
mutant-0.3.0.beta7 lib/mutant/color.rb
mutant-0.3.0.beta6 lib/mutant/color.rb
mutant-0.3.0.beta5 lib/mutant/color.rb
mutant-0.3.0.beta4 lib/mutant/color.rb
mutant-0.3.0.beta3 lib/mutant/color.rb
mutant-0.3.0.beta2 lib/mutant/color.rb