class String

Public Instance Methods

attr(attr) click to toggle source
# File lib/easy-color.rb, line 70
def attr(attr)
  if $stdout.isatty
    "\033[#{($attrs[attr])}m#{self}\033[0m" if valid(:attr => attr)
  else
    "#{self}"
  end
end
bg(color) click to toggle source
# File lib/easy-color.rb, line 62
def bg(color)
  if $stdout.isatty
    "\033[#{($color[color]+10)}m#{self}\033[0m" if valid(:color => color)
  else
    "#{self}"
  end
end
fg(color) click to toggle source
# File lib/easy-color.rb, line 54
def fg(color)
  if $stdout.isatty
    "\033[#{$color[color]}m#{self}\033[0m" if valid(:color => color)
  else
    "#{self}"
  end
end
method_missing(m, *args, &block) click to toggle source
# File lib/easy-color.rb, line 78
def method_missing(m, *args, &block)
  if $color.keys.include?(m)
    fg(m)
  elsif $attrs.keys.include?(m)
    attr(m)
  else
    raise NoMethodError, "Undefined method '#{m.inspect}'."
  end
end
valid(args) click to toggle source
# File lib/easy-color.rb, line 44
def valid(args)
  if args.keys.include? :color and $color.keys.include? args[:color]
    true
  elsif args.keys.include? :attr and $attrs.keys.include? args[:attr]
    true
  else
    false
  end
end