27 Jul, 2009, kiasyn wrote in the 1st comment:
Votes: 0
# 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.)
27 Jul, 2009, Runter wrote in the 3rd comment:
Votes: 0
David Haley said:
Won't work for frame_str of len > 1


Why not?
27 Jul, 2009, David Haley wrote in the 4th comment:
Votes: 0
It doesn't adjust the width correctly. That is, you will end up something potentially much larger than 80 if you have a multi-character frame_str.
27 Jul, 2009, Runter wrote in the 5th comment:
Votes: 0
David Haley said:
It doesn't adjust the width correctly. That is, you will end up something potentially much larger than 80 if you have a multi-character frame_str.


That's true. Although I think it would be pretty easy to change the function to get the length correct even with multiple character string.
27 Jul, 2009, David Haley wrote in the 6th comment:
Votes: 0
Yes, it is quite easy in fact, I was just point out the bug^H^H^Hfeature. :wink:
0.0/6