# Public domain, use as you will, no warranty. module Utils class Formatter # Frame some text, eg # – City Center ———————————————————– def self.frame_text text, frame_str = '-', width = 80, offset=2 stripped_text = ColorFilter.strip_color( text ) "#{frame_str*offset} #{text} #{frame_str*((width-4)-(stripped_text.length))}" end end end
27 Jul, 2009, David Haley wrote in the 2nd comment:
Votes: 0
Won't work for frame_str of len > 1 (so maybe frame_char would be a better argument name). I'm guessing that width - 4 is supposed to be width - offset - 2? (2, to account for the two spaces.)