What is a good way to fill this list of chains of the same length?

advertisements

Here's a puzzle: I have a list of strings each in a format:

\w+==============================\w+

The words on both sides of the ============================== could be different lengths. What's a good way to pad each string with more = so that all strings have an equal length? There should be a minimum of 30 = characters in between the words.

ie, I have this list:

[ "Hello World==============================Bye!",
  "This==============================Should",
  "Be==============================Padded nicely!"]

Turned into:

[ "Hello World===============================Bye!",
  "This====================================Should",
  "Be==============================Padded nicely!"]


a = [ "Hello World===============================Bye!",
  "This====================================Should",
  "Be==============================Padded nicely!"]

max = a.map(&:length).max
a.map{|l| l.sub(/(?:==)/, "=" * (max - l.length))}