# # = clothesline.rb # # *Cloth chainer. # # Copyright (c) 2004 Christian Neukirchen # # Written & maintained by Christian Neukirchen # # # This program is free software. You can re-distribute and/or # modify this program under the same terms of ruby itself --- # Ruby Distribution License or GNU General Public License. # class ClothesLine def self.parse(string, override=Object) instance = new *string.strip.split(/[ ,|]+/).map { |klass| unless override.constants.include? klass require klass.downcase.gsub(/::/, '/') end override.const_get(klass) } instance.instance_eval { @override = override } instance end attr_reader :classes def initialize(*classes) @classes = classes @override = Object end def new(str) # Fake instantiation! @result = @classes.inject(str) { |result, klass| if klass.kind_of? Array klass.first.new(result).to_html(*klass[1..-1]) else klass.new(result).to_html end } self end def to_html @result end def to_clothesline @classes.map { |c| c.to_s.gsub(/#{@override}::/, '') }.join(" ") end def ==(other) @classes == other.classes end end