class Glitz::ColoredString
Public Class Methods
new(string)
click to toggle source
# File lib/glitz.rb, line 69 def initialize(string) @string = string @effects = [] end
Public Instance Methods
colorize(options = {})
click to toggle source
# File lib/glitz.rb, line 74 def colorize(options = {}) @foreground = COLORS[options.delete(:foreground)] + 30 if options.key? :foreground @background = COLORS[options.delete(:background)] + 40 if options.key? :background @effects += Array(options.delete(:effects)).collect{|s| EFFECTS[s]} if options.key? :effects self end
method_missing(method_name, *args, &block)
click to toggle source
# File lib/glitz.rb, line 92 def method_missing(method_name, *args, &block) self.to_s.send(method_name, *args, &block) end
to_s()
click to toggle source
# File lib/glitz.rb, line 86 def to_s "\033[#{[@effects, @foreground, @background].flatten.compact.uniq.join(';')}m#{@string}\033[0m" end
Also aliased as: to_str
uncolorize()
click to toggle source
# File lib/glitz.rb, line 82 def uncolorize @string end