class Colorlib::ColoredCompound

Public Class Methods

new() click to toggle source
# File lib/colorlib/colored_compound.rb, line 6
def initialize
  @strings = []
end
register_maker(type, &block) click to toggle source
# File lib/colorlib/colored_compound.rb, line 29
def self.register_maker(type, &block)
  @@makers[type] = block
end

Public Instance Methods

<<(whatever)
Alias for: append
append(whatever) click to toggle source
# File lib/colorlib/colored_compound.rb, line 10
def append(whatever)
  @strings << whatever.is_a?(ColoredString) ? whatever : ColoredString.new(whatever.to_s)
  self # to return it
end
Also aliased as: <<
make(target) click to toggle source
# File lib/colorlib/colored_compound.rb, line 17
def make(target)
  unless (maker = @@makers[target])
    raise 'Invalid Target'
  end
  prev = ColorAttribute.new
  ret = ''
  @strings.each do |string|
    ret += maker.call string, prev
  end
  ret
end