module Chromate::Formattable

The `Formattable` module allows any class easy access to Chromate formatting, so long as it provides an `effects` method, which is expected to return an `EffectSet`.

Private Class Methods

format_attr(name, question_name = name.to_s + '?') click to toggle source

Introduce a format attribute. Each format attribute comes with two methods, which generally differ only by addition of a '?' character ( although this behavior can be overriden). The first method sets the format attribute with the given name, and the second queries whether it is set. @param name [Symbol] the name of an attribute @param question_name [Symbol] the name of the method to query whether the

attribute is set

@api private

# File lib/chromate/formattable.rb, line 20
    def self.format_attr(name, question_name = name.to_s + '?')
      if EFFECTS.include?(name)
        module_eval(<<-EOF
          define_method :#{name} do
            effects << Effect[:#{name}]
            self
          end

          define_method :#{question_name} do
            effects.include?(Effect[:#{name}])
          end
        EOF
        )
      else
        raise ArgumentError, "no such effect: #{name}"
      end
    end

Public Instance Methods

bg(what) click to toggle source

Set the background and return self. @param what [Object] an object describing the background color (see

{Chromate::Color::[]})

@return [Formattable] self

# File lib/chromate/formattable.rb, line 59
def bg(what)
  effects << Color[what].as_bg
  self
end
fg(what) click to toggle source

Set the foreground and return self. @param what [Object] an object describing the foreground color (see

{Chromate::Color::[]})

@return [Formattable] self

# File lib/chromate/formattable.rb, line 48
def fg(what)
  effects << Color[what]
  self
end
to_s() click to toggle source

@return [String]

# File lib/chromate/formattable.rb, line 65
def to_s
  effects + self + OFF
end